A Jr. Developer asked me why a primary key not null in SQL Server. A primary key uniquely identifies a row in a table and a NULL can’t identify any row. Moreover, a primary key is used to find rows in a table and is essential for indexing and maintaining data.
Let’s see what happens if we try to add a primary key constraint on a null able column.
As shown in above image, the SQL Server terminates with error when creating primary key on a null able column.
Let’s see the behavior when defining composite primary key.
The SQL Server again terminates with error. Thus all columns participating in a primary key should be not null.
Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook