The primary key ensures the uniqueness of data for a column and this means that you can't add more than one record with the same key. In addition, using the instruction "INSERT.... ON DUPLICATE KEY/ON CONFLICT.... UPDATE" can be used to force an update of selected row columns if the key already exists. This eliminates the need to use the SELECT statement to check if the PK is free.
A good practice affecting the performance of a database application is the use of AUTO_INCREMENT (MySQL) / IDENTITY (PostgreSQL, SQLServer) attributes in primary keys, which means autonumbering. The PK of each new record gets a new unique number. Please note that autonumbering can be used for only one table column and it must be an INTEGER column.
How to set primary key in SqlDBD?
You can add a primary key in two ways:
1. select the INTEGER type column and in the properties of this column enable AUTO_INCREMENT/IDENTITY - this action, in addition to enabling autonumbering, will create the primary key for the column (if it does not already exist).
2. select the table and in the properties window on the right, in the "Indexes and keys" section, click "Add index" - an index will be added, the type of which should be changed from INDEX to PRIMARY. Then, in the "Columns" section (index properties), click "Edit", select a column (or columns) from the list and confirm by clicking the icon next to it.
The second method, although it requires a bit more time, allows you to precisely set the columns of the primary key. However, in most cases the first method is sufficient.