Unique and Primary Keys

The UNIQUE constraint uniquely identifies each record in a database table. The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint defined on it. Note that you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.

Certain restrictions must be obeyed when working with unique and primary keys:

  • A table or view can have only one primary key.
  • A composite key cannot have more than 32 columns.
  • You cannot designate the same column or combination of columns as both a primary key and a unique key.
  • Some column types such as LOB, LONG, VARRAY, NESTED TABLE, REF are not supported for unique or primary keys.

Creating and Editing a Key

  1. In the Database Explorer window, right-click a required table.
  2. Click Edit Table in the shortcut menu.
  3. In the Table menu, click either New Primary Key or New Unique Key.
  4. Add required columns to the key and click OK.

When the Table Editor is open, you can switch to the Constraints tab, and create (or edit) a key using the shortcut menu.

To delete a key, select a required key, and click Delete Constraint in the shortcut menu.