Manage keys

This topic describes how to create and manage keys from Database Explorer.

A unique constraint ensures that the values in a column—or in a combination of columns (a composite unique key)—are not duplicated.

  • For a single-column unique key, no two rows can have the same value. However, the column can contain NULL values.
  • For a composite unique key, no two rows can have the same combination of values across the key columns. A row with NULL in all key columns automatically satisfies the constraint. However, two rows that share the same values in non-null columns and contain NULL in one or more key columns violate the constraint.

A primary key constraint identifies a column or set of columns as the primary key of a table or view. A composite primary key uses multiple columns. A primary key combines unique and NOT NULL constraints:

  • Each key value must be unique across all rows.
  • Columns that are part of the primary key can’t contain NULL values.

Note

In a composite primary key, each column that participates in the key must be defined as NOT NULL. Nullable columns are not allowed.

When working with unique and primary keys, follow these rules:

  • A table or view can have only one primary key.
  • A composite key can include up to 32 columns.
  • The same column or combination of columns can’t be both a primary key and a unique key.
  • Some column types, such as LOB, LONG, VARRAY, NESTED TABLE, and REF, aren’t supported for primary or unique keys.

Create a foreign key

1. In Database Explorer, right-click the Keys node and select New Foreign Key.

2. On the Constraints tab of Table Designer:

2.1. Right-click the grid and select Add Foreign Key.

2.2. Configure the foreign key properties.

3. Click Apply Changes.

Create a primary key

1. In Database Explorer, right-click the Keys node and select New Primary Key.

2. On the Constraints tab of Table Designer:

2.1. Right-click the grid and select Add Primary Key.

2.2. Configure the primary key properties.

3. Click Apply Changes.

Create a unique key

1. In Database Explorer, right-click the Keys node and select New Unique Key.

2. On the Constraints tab of Table Designer:

2.1. Right-click the grid and select Add Unique Key.

2.2. Configure the unique key properties.

3. Click Apply Changes.

Edit a key

1. In Database Explorer, right-click the key you want to edit (primary, foreign, or unique) and select Edit Primary Key, Edit Foreign Key, or Edit Unique Key.

2. On the Constraints tab of Table Designer, update the key properties.

3. Click Apply Changes.

Delete a key

1. In Database Explorer, right-click the key you want to delete and select Delete, or press Delete.

2. Click Yes to confirm deleting the key, or No to discard the operation.

Rename a key

1. In Database Explorer, right-click the key you want to rename and select Rename, or press F2.

2. Enter the new key name.

3. Click Yes to confirm the renaming of the key.

View the key properties

View the key properties in one of these ways:

  • Double-click the required key.
  • In Database Explorer, right-click the key and select Show Details.

Object Viewer opens, displaying detailed information about the key.

Refresh the key

To update the key to reflect the latest changes, in Database Explorer, right-click the key or Keys node and select Refresh, or press F5.

Open the Properties pane

To open the Properties pane, in Database Explorer, right-click the key and select Properties, or press F4.

Filter keys

1. In Database Explorer, right-click the Keys node and select Filter.

2. In the Filter Settings dialog, configure the filter parameters.

3. Click OK.

Note

When you expand the Keys node, the number of objects it contains appears in parentheses next to the node name. This number changes based on your filter settings.