SQL Server › Constraints (Primary Key, Foreign Key, Check & Unique)
What is a primary key constraint, and why is it important for a database table?
BeginnerAnswer
A primary key constraint uniquely identifies each row in a table, ensuring no two rows can have the same value in that column, and it also automatically prevents that column from containing NULL values, making it the reliable way other tables can reference a specific row.
CREATE TABLE Customers (
CustomerId INT PRIMARY KEY,
Name VARCHAR(100)
);Real-world example An online store uses CustomerId as the primary key for its customers table, guaranteeing that every customer record can always be uniquely identified and referenced by other tables like orders.