What is a Primary Key?
Keys are used to access tables, and come in two varieties: Primary Keys and Foreign Keys. A Primary Key uniquely identifies a record in a table, while a Foreign Key accesses data in some other related table via its Primary Key. This topic describes Primary Keys; Foreign Keys are described in the Foreign Keys topic.
Define a Simple Primary Key
If a Primary Key consists of a single column, it is very easy to define.
1. | Right-click on the table in a diagram to display the context menu. Select the menu option. |
2. | In the Attributes dialog, select the column that makes up the Primary Key. |
3. | Select the checkbox and click on the button. |
A stereotyped operation is automatically created. It is this operation that defines the Primary Key for the table. To remove a Primary Key, simply delete this operation.
Define a Complex Primary Key
Often, a Primary Key consists of more than one column. For example, a column LastName might not be unique within a table, so a Primary Key is created from the LastName, FirstName and DateOfBirth columns. Perform the following steps to create a complex Primary Key:
1. | Follow the steps above to create a Simple Primary Key. It doesn't matter which column you choose. |
2. | Right-click on the table in a diagram to open the context menu. Select the menu option. |
3. | Select the Primary Key operation (its name begins with PK_) and then click on the Columns tab. |
4. | To add a column to the Primary Key, click on the button, select a column from the Column Name list box, and then click on the button. |
5. | Click on the buttons (up and down arrow) to change the order of columns in the Primary Key, if necessary. |
Define a Primary Key Name Template
To define the name template for a Primary Key, follow the steps below:
1. | Select the menu option. The DDL page of the Options dialog displays.

|
2. | Click on the button. The DDL Name Template dialog displays, showing the default name templates.

|
3. | Edit or replace the template in the field. |
See Also