Topic
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

Access

Method

Ribbon

Design > Tools > Database Builder > Click on Table name

Context Menu

In diagram | Right-click on Table | Features & Properties | Operations

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:

  • In the Database Builder, click on a Table with one or more defined columns, and click on the 'Columns' tab, or
  • On a diagram, click on a Table and press F9 to display the 'Columns' tab

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:

  • In the Database Builder, click on a Table with one or more defined columns, and click on the 'Constraints/Indexes' tab, or
  • On a diagram, click on a Table and press F10 to display the 'Constraints/Indexes' tab

2

Overtype the New Constraint text with the Primary Key name, press the Enter key 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.

  • Fill Factor is a numeric value between 0 and 100
  • Is Clustered is a boolean value that determines the physical order of how the data is stored; for most DBMSs the Is Clustered property defaults to True for Primary Keys
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:

  • In the Database Builder, click on the Table with the Primary Key, and click on the 'Columns' tab, or
  • On a diagram, click on a Table and press F9 to display the 'Columns' tab

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:

  • In the Database Builder, click on the Table with the Primary Key, and click on the 'Constraints/Indexes' tab, or
  • On a diagram, click on a Table and press F10 to display the 'Constraints/Indexes' tab

2

Unassign the columns on the PK constraint, as necessary.

Database Table Constraints

Notes

  • Warning: Enterprise Architect assumes that Primary Key constraints have at least one column assigned to them; however, Enterprise Architect does not enforce this rule during modeling
    If DDL is generated for a Table whose Primary Key has no column assigned, that DDL will be invalid

Learn more