Primary Key

A Primary Key is a Column or set of Columns whose value(s) identify a row in a table as unique.

A single-Column Primary Key is commonly a unique ID. A multi-Column, or composite, Primary Key might include, for example: Patient, Visit, Test, if each test was conducted only once at a particular visit. None of the Columns that is part of a Primary Key can have a null value in any row.

The system automatically creates an index based on the primary key, which it uses to enforce a unique constraint. The index also speeds up queries on the table.

When you define a Primary Key, the system enforces constraints on the data:

  • The Column value(s) must serve as a unique identifier for each row.
  • No value in a key Column can be null. Columns that are part of a Primary Key must have the Nullable attribute set to No (the check box must be cleared).

To define a Primary Key:

  1. Select Primary Key from the Type drop-down list. The system refreshes the lower portion of the screen and lists all the Columns you have defined in the current Table instance in the Table Columns side of the shuttle.
  2. Select the Column or Columns you want to be part of the primary key and move them into the Primary Key side of the shuttle. You can use Shift+Click or Ctrl+Click to select the Columns. You can double-click to move them or use the arrows.
  3. If necessary, use the Up and Down arrows to reorder the Columns in the key. You should have the most general Column at the top and the most granular at the bottom. For example, if your Primary Key is Patient, Visit, Test, you should list them in that order so that you can use the automatically generated index.
  4. Click Apply.