Sobes.tech
Middle+

Mis on primaarvõti ja millised on selle kohustuslikud piirangud?

sobes.tech AI

Vastus AI-lt

Primary Key is a unique identifier for a record in a database table. It ensures the uniqueness of each row and is used for quick search and establishing relationships with other tables.

Mandatory constraints of the primary key:

  • Uniqueness: the values in the column(s) of the primary key must be unique to distinctly identify the record.
  • NOT NULL: the values cannot be NULL, as the key must uniquely identify the record.

Example in SQL:

CREATE TABLE Users (
  id INT PRIMARY KEY, -- unique and NOT NULL
  name VARCHAR(100)
);