AFM341 Lecture Notes - Lecture 9: Class Diagram, Social Security Number, Unique Key
e.g. "State" class in figure 3
-
2 collectively defines all the states. Each state is an instance in
that class, and each state would be identified by a unique primary key such as abbreviations
AR, CA, WA, etc.
â—‹
The primary key must uniquely identify each instance of the class (or row of the table).
Avoid duplication such as names

The primary key cannot be null (blank) under any circumstances. Avoid using
attributes for the primary key that are potentially unavailable for any instance of the
class. e.g. not everyone has a Social security number.

The PK should be controlled by the organization that assigns it
PK with sequential values makes it easier to recognize gaps in the data
All else equal, short PK is better than longer ones because ease of data entry,
indexing, and retrieval.

There are often several candidates for the primary key of a class or database table. How to
pick?
â—‹
A foreign key is linked to the PK of another table to support a defined association.
â—‹
e.g. in figure 3-3, the Auto class would include a FK to match the PK for the Person class to
support the Owns association
â—‹
In figure 3-4, the PK of the Customer Table is Customer_Number. The FK Customer_Number
in the Order Table allows rows in the Order table to be linked to corresponding rows in the
Customer Table.
â—‹
A foreign key (FK) is an attribute or combination of attributes that allows tables to be linked
together.
•
Aside from association which is the generic relationship between two classes•
Generalization (or inheritance)â—‹
Aggregationâ—‹
Compositionâ—‹
UML includes modeling notation for other types of relationships:•
Other relationships
note that these special relations can also be modeled with associations •
AFM 341 Page 3
Document Summary
E. g. state class in figure 3-2 collectively defines all the states. Each state is an instance in that class, and each state would be identified by a unique primary key such as abbreviations. There are often several candidates for the primary key of a class or database table. The primary key must uniquely identify each instance of the class (or row of the table). The primary key cannot be null (blank) under any circumstances. Avoid using attributes for the primary key that are potentially unavailable for any instance of the class. e. g. not everyone has a social security number. The pk should be controlled by the organization that assigns it. Pk with sequential values makes it easier to recognize gaps in the data. All else equal, short pk is better than longer ones because ease of data entry, indexing, and retrieval. A foreign key (fk) is an attribute or combination of attributes that allows tables to be linked together.