Database Reference
In-Depth Information
Practical Examples
Let's get backto the rookery database that we created and altered in Chapters 4 and 5 for
more involved examples of inserting data into tables. If you haven't created those tables
yet, I recommend you go back and do that before proceeding with this chapter.
Your natural tendency when putting data into a database will be to start by adding data to
the main or primary table of the database first and to worry about ancillary or reference
tables later. That will work well enough, but you may be creating more work for yourself
than needed. Starting with the main table is more interesting, and entering data in reference
tables is more tedious. But that's the way of databases: they are tedious. It's inescapable.
Nevertheless, we don't have to create all of the tables we will need for a database before
entering data; we don't need to enter data into all of the secondary tables before working on
the primary tables. It will be difficult to plan ahead for all of the possible tables that will be
needed. Instead, database development is generally always a work in progress. You will of-
ten add more tables, change the schema of existing tables, and shift large blocks of data
from one table to another to improve performance and to make the management of the
database easier. That takes some of the tediousness out of databases and makes database
management interesting.
With that approach in mind, we'll enter data in some of the tables, using some simple logic
to decide which table to work on first. Remember how we are categorizing birds: a bird
species is a member of a bird family, and a bird family is part of a bird order. The birds
table needs the family_id to join with the bird_families table, and the
bird_families table needs an order_id from the bird_orders table to join with
it. So, we'll add data to bird_orders first, then to bird_families , and then to
birds .
Most people don't know the scientific names of birds, bird families, and bird orders.
However, you can find this information on Wikipedia and sites dedicated specifically to
bird-watching and ornithology. But there's no need for you to do research about birds to
participate in this topic. I'll provide you with the information to enter a few rows for each
table, and you can download complete tables from my website .
The Table for Bird Orders
Before entering data in the bird_orders table, let's remind ourselves of the structure of
the table by executing the following SQL statement:
DESCRIBE bird_orders;
Search WWH ::




Custom Search