Interview Question

What is a primary key?

A primary key uniquely and non-nullably identifies table rows.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

A primary key is a table constraint that uniquely identifies each row. • Its values must be unique and not null. • A table can have only one primary-key constraint, although it may contain several columns. • A primary key usually creates a unique index in PostgreSQL.

💡 SQL Example

CREATE TABLE users (user_id integer PRIMARY KEY, email text NOT NULL);

Result

CREATE TABLE

⚡ Quick Revision

A primary key uniquely and non-nullably identifies table rows.