Adding Keys to a Relationship

How can I add other Key columns to a M:N relationship?

When you create a Many to Many (M:N) relationship between two entities, you create a new object type called a Composite Entity. A composite entity behaves exactly the same as a weak entity, with it's primary key comprised of the primary keys of the entities to which it is related. There are occassions however, when you may need to add a further column to be part of the primary key of the composite entity. Consider the following example:

We have created a Many to Many relationship OrderLine, between PurchaseOrder and Product that we want to use to specify each line in the purchase order. However, we want to be able to have the same Product on more that one line in the order, therefore, we will introduce an additional column to the primary key called the OrdLnNum (order line number) in the OrderLine composite entity. Refer to the Entity Relationship Diagram (ERD) OrderLine properties:

Notice that the implicit foreign keys do not appear in the relationship's properties in the conceptual model and that the OrdLnNum is the explicit key column.

If we now generate a Data Structure Diagram (DSD) from the ERD, we will find that the primary key of the OrderLine is the combined columns of all three objects:

In the above example, we have ordered the columns so that the OrdLnNum is listed before the (default) ProductID column.

See also: Foreign Keys, Foreign Primary Keys, Renaming Foreign Key Columns and Ordering Rows in Grids