A primary key is a column or combination of columns that uniquely identifies each row in a table. A primary key cannot contain NULL values.
Reliable row identification is essential for maintaining data integrity and creating relationships between tables.
EmployeeID can be used as the primary key in an Employees table because each employee should have a unique identifier.
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
EmployeeName VARCHAR(100),
Salary DECIMAL(12,2)
);
Primary keys are used in customer, employee, account, transaction, order, product, and many other business tables.
- A primary key uniquely identifies rows.
- Primary key values cannot be NULL.
- A table normally has one primary key constraint.
- A primary key can contain multiple columns.
- Primary keys help establish relationships between tables.
What is a primary key?
A primary key is a column or combination of columns that uniquely identifies each row in a table.
Can a primary key contain NULL?
No. A primary key must uniquely identify every row and cannot contain NULL values.