Database Design for Mere Mortals: A Hands-On Guide to Relational Database Design

   

Reviewing the Initial Table Structures

Now that the fundamental table definitions are complete, you need to conduct interviews with users and management to review the work you've done so far. This set of interviews is fairly straightforward and should be relatively easy to conduct.

During these interviews, you will accomplish these tasks :

When you've completed the interviews, you'll move to the next phase of the database-design process and establish field specifications for every field in the database.

CASE STUDY

It's now time to establish keys for each table in the Mike's Bikes database. As you know, your first order of business is to establish candidate keys for each table. Let's say you decide to start with the CUSTOMERS table in Figure 8.9.

Figure 8.9. The CUSTOMERS table structure in the Mike's Bikes database.

As you review each field, you try to determine whether it conforms to the Elements of a Candidate Key. You determine that S TATUS , C UST H OME P HONE , and the combination of C UST F IRST N AME and C UST L AST N AME are potential candidate keys, but you're not quite certain whether any of them will completely conform to all of the elements. So you decide to test the keys by loading the table with sample data as shown in Figure 8.10.

Figure 8.10. Testing candidate keys in the CUSTOMERS table.

Always remember that a field must comply with all of the Elements of a Candidate Key in order to qualify as a candidate key. You must immediately disqualify the field if it does not fulfill this requirement.

As you examine the table, you draw these conclusions:

These findings convince you to establish an artificial candidate key for this table. You then create a field called C USTOMER ID, confirm that it complies with the requirements for a candidate key, and add the new field to the table structure with the appropriate designation.

Figure 8.11 shows the revised structure of the CUSTOMERS table.

Figure 8.11. The CUSTOMERS table with the new artificial candidate key, C USTOMER ID.

Now you'll repeat this procedure for each table in the database. Remember to make certain that every table has at least one candidate key.

The next order of business is to establish a primary key for each table. As you know, you select the primary key for a particular table from the table's pool of available candidate keys. Here are a few points to keep in mind when you're choosing a primary key for a table with more than one candidate key:

You begin by working with the EMPLOYEES table in Figure 8.12. As you review the candidate keys, you decide that E MPLOYEE N UMBER is a much better choice for a primary key than the combination of E MP F IRST N AME and E MP L AST N AME because Mike's employees are already accustomed to identifying themselves by their assigned numbers . Using E MPLOYEE N UMBER makes perfect sense, so you select it as the primary key for the table.

Figure 8.12. The EMPLOYEES table structure in the Mike's Bikes database.

Now you perform one final task before you designate E MPLOYEE N UMBER as the official primary key of the table: You make absolutely certain that it exclusively identifies the value of each field within a given record. So, you test E MPLOYEE N UMBER by following these steps:

  1. Load the EMPLOYEES table with sample data.

  2. Select a record for test purposes and note the current value of E MPLOYEE N UMBER .

  3. Examine the value of the first field (the one immediately after E MPLOYEE N UMBER ) and ask yourself this question:

    Does this primary key value exclusively identify the current value of <fieldname> ?

    1. If the answer is yes, move to the next field and repeat the question.

    2. If the answer is no, remove the field from the table , move to the next field and repeat the question. (Be sure to determine whether you can add the field you just removed to another table structure, if appropriate, or discard it completely because it is truly unnecessary.)

  4. Continue this procedure until you've examined every field value in the record.

You know that you'll have to remove any field containing a value that E MPLOYEE N UMBER does not exclusively identify. E MPLOYEE N UMBER does exclusively identify the value of each field in the test record, however, so you use it as the official primary key for the EMPLOYEES table and mark its name with the letters "PK" in the table structure. You then repeat this process with the rest of the tables in Mike's new database until every table has a primary key.

Remember to keep these rules in mind as you establish primary keys for each table:

As you work through the tables in Mike's database, you remember that the SERVICES table is a subset table. You created it during the previous stage of the design process (in Chapter 7), and it represents a more specific version of the subject represented by the PRODUCTS table. The P RODUCT N AME field is what currently relates the PRODUCTS table to the SERVICES subset table. You now know, however, that a subset table must have the same primary key as the table to which it is related , so you'll use P RODUCT N UMBER (the primary key of the PRODUCTS table) as the primary key of the SERVICES table. Figure 8.13 shows the PRODUCTS and SERVICES tables with their primary keys.

Figure 8.13. Establishing the primary key for the SERVICES subset table.

The last order of business is to conduct interviews with Mike and his staff and review all the work you've performed on the tables in the database. As you conduct these interviews, make certain you check the following:

By the end of the interview, everyone agrees that the tables are in good form and that all the subjects with which they are concerned are represented in the database. Only one minor point came up during the discussions: Mike wants to add a C ALL P RIORITY field to the VENDORS table. There are instances in which more than one vendor supplies a particular product, and Mike wants to create a way to indicate which vendor he should call first if that product is unexpectedly out of stock. So, you add the new field to the VENDORS table and bring the interview to a close.


   
Top

Категории