Defining Field Specifications for Each Field in the Database

   

Using Unique, Generic, and Replica Field Specifications

Earlier in this chapter, you learned that you could define a specification as Unique , Generic , or Replica . You can ensure that you define the appropriate type of specification for a given field by following these simple guidelines:

  • Use a Unique specification for any field that will appear only once within the entire database or for a field that serves as a primary key .

  • Use a Generic specification for a field that serves as a template for other fields within the database. Remember to use a nonspecific field name and element settings that are as broad and general as possible.

  • Use a Replica specification for a field that you base on a given generic field or for a field that serves as a foreign key within a table relationship.

Figure 9.8 shows the complete Unique field specification for a V ENDOR ID N UMBER field.

Figure 9.8. Unique field specification for the V ENDOR ID N UMBER field.

graphics/09fig08.jpg

Here are a few things to note about this specification:

  1. This field also appears in the PRODUCTS table, as indicated by the Shared By general element. This is both reasonable and necessary because each product must be associated with a specific vendor. (You'll learn more about this type of issue in the next chapter.)

  2. Examine the settings for the Uniqueness, Null Support, Required Value, and Edit Rule logical elements. They are set in this manner because the Key Type element is set to "Primary." You should, in fact, use these element settings for any field that serves as a primary key.

  3. The Comparisons Allowed logical element is set to "Same FieldEquals" so that a user can compare V ENDOR ID N UMBER values in the VENDORS table to V ENDOR ID N UMBER values in the PRODUCTS table.

  4. The Comparisons Allowed logical element is also set to "Value ExpressionEquals" so that a user can compare V ENDOR ID N UMBER values to some arbitrary numeric value.

Figure 9.9 shows the complete Generic field specification for a generic STATE field.

Figure 9.9. Generic field specification for a generic S TATE field.

graphics/09fig09.jpg

Take note of these particular items:

  1. The description is very general, as it should be for this type of specification.

  2. The setting of the Display Format physical element is in the form of an instruction. This demonstrates that you have a great deal of flexibility in the way you set this element.

  3. The Range of Values logical element is appropriately broad.

  4. The Comparisons Allowed logical element is set to "Value ExpressionEquals" so that a user can compare S TATE values to some arbitrary two-character alphanumeric value.

  5. The Operations Allowed logical element is set to "Other FieldsConcatenation" so that a user can concatenate a given S TATE value to the value of some other alphanumeric field.

  6. The Operations Allowed logical element is also set to "Value ExpressionConcatenation" so that a user can concatenate a given S TATE value to some arbitrary alphanumeric value.

This field (and its specification) now serves as a template for all other state fields you create in the database. For example, you can create a V END S TATE field based on the generic S TATE field. You'll define a Replica specification for the V END S TATE field that is based on the S TATE field's Generic specification. Although the V END S TATE field's Replica specification draws its initial element settings from the S TATE field's Generic specification, you can modify any of the Replica specification's element settings so that you can completely customize them for the V END S TATE field. Figure 9.10 shows the customized Replica field specifications for the V END S TATE field.

Figure 9.10. Customized Replica field specification for the V END S TATE field.

graphics/09fig10.jpg

Here are a few things to note about this specification:

  1. The field name (V END S TATE ) accurately denotes what the field represents.

  2. The label ("State") is what the user will see on visual displays and printed documents.

  3. The Source Specification general element properly references the generic S TATE field's specification.

  4. The Description element is now specific to this field. Recall that the description is more general in the source specification.

  5. A default value has been set for this field; there is no such value in the source specification.

  6. The Range of Values element is now specific to this field; it was much broader in the source specification.

In the next chapter, you'll learn how to define a Replica field specification for a field that serves as a foreign key.


   
Top


Database Design for Mere Mortals[c] A Hands-On Guide to Relational Database Design
Database Design for Mere Mortals: A Hands-On Guide to Relational Database Design
ISBN: 0201694719
EAN: 2147483647
Year: 2002
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net