Middle+
What is a primary key and what are its mandatory constraints?
sobes.tech AI
Answer from AI
Primary Key is a unique identifier of a record in a database table. It ensures the uniqueness of each row and is used for quick search and linking with other tables.
Mandatory constraints of the primary key:
- Uniqueness: values in the primary key column(s) must be unique to unambiguously identify a record.
- NOT NULL: values cannot be NULL, as the key must uniquely identify a record.
Example in SQL:
CREATE TABLE Users (
id INT PRIMARY KEY, -- unique and NOT NULL
name VARCHAR(100)
);