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:
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.
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.
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.
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.