Back to articles list
- 2 minutes read

Always Define a Primary Key for Each Table

In a relational database, each table should have a primary key (PK). A primary key has multiple advantages for a table, including a:

UNIQUE constraint

A primary key adds a UNIQUE constraint to a column. This ensures that the data in that column is not duplicated. If an object with the same primary key value is already present in the table, we should update the object instead of creating another one.

Database index

A database index is automatically created together with a primary key. This makes data searches faster. Indexes work like the table of contents in a book – they allow the database to quickly locate a specific row without scanning the whole table.

How to Set a Primary Key in Vertabelo

To set the primary key in Vertabelo, select the table. In the right pane, find the Columns section and check the PK box next to the column name.

Note that you can choose multiple columns to create a composite (i.e. multi-column) primary key.

Always Define a Primary Key for Each Table

Vertabelo checks if each table has a primary key; if a table doesn’t have a PK, Vertabelo displays a warning. You can find out more about model validation in Vertabelo here.

Always Define a Primary Key for Each Table

There is also a special property section for each table called Primary key. This section is useful when your table needs a multicolumn key. Here, you can set the order of the columns used to form the PK and set the key name; this will be the name of the database constraint for this key.

Always Define a Primary Key for Each Table
go to top

Our website uses cookies. By using this website, you agree to their use in accordance with the browser settings. You can modify your browser settings on your own. For more information see our Privacy Policy.