| Lesson 13 | All-key relations |
| Objective | Describe all-key relations. |
When a table is created to represent an entity, it is possible that every column in the table will be part of the entity's primary key.
As an example, examine the entities in the following graphic.
As an example, examine the entities in the following graphic.
The entity named Available_In contains two columns, both of which are part of the entity's primary key.
When every field in a relation is part of the primary key for that relation, the relation is referred to as anall-key relation .
All-key relations are valuable because they enable you to create many-to-many relationships between tables in the database without incurring the problems of many-to-many relationships.
AvailableIn provides just such a bridge between the ITEM and LANGUAGES tables. Rather than including fields in the ITEM table to record in which languages the CD is available (which is bad design, as we will see), or creating a many-to-many relationship (which is also bad design), users can enter as many languages as they need to describe each Stories on CD product. The information about languages is stored in the AvailableIn table.
The next lesson describes foreign keys.
When every field in a relation is part of the primary key for that relation, the relation is referred to as anall-key relation .
All-key relations are valuable because they enable you to create many-to-many relationships between tables in the database without incurring the problems of many-to-many relationships.
AvailableIn provides just such a bridge between the ITEM and LANGUAGES tables. Rather than including fields in the ITEM table to record in which languages the CD is available (which is bad design, as we will see), or creating a many-to-many relationship (which is also bad design), users can enter as many languages as they need to describe each Stories on CD product. The information about languages is stored in the AvailableIn table.
The next lesson describes foreign keys.
- all-key relation: A relation in which every field is a member of the relation's primary key
- foreign key: A field (or combination of fields) used to link tables; a corresponding primary key field occurs in the same database