Junior — Middle
Can you explain what a primary key in a database is and what it is used for?
sobes.tech AI
Answer from AI
A Primary Key in a database is a unique identifier for each record in a table. It guarantees that each row can be uniquely identified.
Main properties of a primary key:
- Uniqueness: primary key values do not repeat in the table.
- Cannot be NULL: each record must have a primary key value.
Using a primary key allows efficient searching, updating, and linking data between tables (through foreign keys).
Example: in the "Users" table, the "user_id" field can be a primary key to uniquely identify each user.