Prev | Next |
Primary Keys
A Primary Key is a column (or set of columns) that uniquely identifies each record in a Table. A Table can have only one Primary Key. Some DBMSs support additional properties of Primary Keys, such as Clustered or Fill Factor.
Access
Ribbon |
Specialize > Tools > Database Builder > Click on Table name |
Context Menu |
In diagram | Right-click on Table | Features & Properties | Constraints/Indexes |
Create a Primary Key
In Enterprise Architect you can create a Primary Key from either the 'Columns' tab or the 'Constraints/Indexes' tab. In either case, when you add a column to a Primary Key constraint, the column is automatically set to be 'Not Null'. Additionally any diagram (assuming the 'Show Qualifiers and Visibility Indicators' option is set) containing the Table element will show the 'PK' prefix against the column name. In this image, see the first column 'id: bigserial'.
Create a Primary Key - from the Columns tab
Step |
Action |
See also |
---|---|---|
1 |
Either:
|
|
2 |
For each column to include in the Primary Key, select the 'PK' checkbox. If a Primary Key constraint is not previously defined for the current Table, the system will create a new constraint using the Primary Key Name template. |
DDL Name Templates |
Create a Primary Key - from the Constraints tab
Step |
Action |
See also |
---|---|---|
1 |
Either:
|
|
2 |
Overtype the New Constraint text with the Primary Key name, press the and click on the 'Type' field drop-down arrow, and select 'PK'. |
Database Table Constraints |
3 |
Assign the required columns to the PK constraint. |
|
4 |
Set the Primary key's extended properties using the property panel.
|
Non Clustered Primary Keys |
Remove columns from a Primary Key
You can remove columns from a Primary Key using either the 'Columns' tab or the 'Constraints/Indexes' tab.
Remove columns from a Primary Key - using the Columns tab
Step |
Action |
See also |
---|---|---|
1 |
Either:
|
|
2 |
Against each column you want to remove from the Primary Key, deselect the 'PK' checkbox. If you have removed all columns from the Primary Key constraint and the Primary Key is no longer needed, it must be manually deleted. |
Remove columns from a Primary Key - using the Constraints/Indexes tab
Step |
Action |
See also |
---|---|---|
1 |
Either:
|
|
2 |
Unassign the columns on the PK constraint, as necessary. |
Database Table Constraints |
Notes
If DDL is generated for a Table whose Primary Key has no column assigned, that DDL will be invalid
Learn more