RubyMine 2022.3 Help

Primary keys

The primary key contains unique values and identifies each row in a table.

For some databases, the primary key cannot contain NULL values. A table can have only one primary key and this primary key can consist of single or multiple columns. When a primary key consists of multiple columns, the data from these columns is used to determine whether a row is unique.

Create a primary key

  1. In the Database tool window (View | Tool Windows | Database), expand the data source tree until the node of a child table.

  2. Right-click a child table and select Modify Table.

  3. In the Modify dialog that opens, click the Add button (the Add button) and select Primary Key.

    Alternatively, select the keys node in the tree, click the Add button (the Add button), and select Primary Key.

  4. Click the Add button (the Add button) in the Columns pane of the primary key editor tab.

  5. In the Column Name, type or select the column that you want to make a primary key.

  6. Click OK.

    Create a primary key

Create a composite primary key

  1. In the Database tool window (View | Tool Windows | Database), expand the data source tree until the node of a child table.

  2. Right-click a child table and select Modify Table.

  3. In the Modify dialog that opens, click the Add button (the Add button) and select Primary Key.

  4. Add the columns that you want to make a primary key of:

    • Click the Add button (the Add button) in the Columns pane of the primary key editor tab.

    • In the Column Name, type or select the column that you want to make a primary key.

  5. Click OK.

    Create a composite primary key

Make a column a primary key

  1. In the Database tool window (View | Tool Windows | Database), expand the data source tree until the node of a child table.

  2. Right-click a child table and select Modify Table.

  3. In the Modify dialog that opens, select the column that you want to make a primary key.

  4. Click the click the vertical ellipsis icon (Settings) next to the column Name field and select Make Primary Key.

    The new primary key will appear under the keys node of the tree. The primary key editing tab will appear next to the column editing one.

  5. Click OK.

    Make a column a primary key
Last modified: 05 December 2022