Why Primary Key doesn`t accept null values? [Resolved]

Posted by Neerajprasadsharma under Sql Server on 5/18/2017 | Points: 10 | Views : 403 | Status : [Member] | Replies : 1
Can anybody explain why the Primary Key doesn`t accept null values?

Contact for Free SQL Server Performance Consulting and Training for you or your Organization.


Responses

Posted by: Neerajprasadsharma on: 5/18/2017 [Member] Bronze | Points: 50

Up
1
Down

Resolved

First , let us learn the basics about Nulls in programming, Null are actually a flag which suggest nonexistent or unknown value.
It is not zero, not an empty string. A value cannot equal to a NULL even two NULL values are equal.

NULL != NULL .
The Primary Key is a Unique Identifies, according to the definition of the Primary Key, every row has to be unique and can be identified uniquely. And null is unknown value, so the primary key cannot accept NULL values.
On the top of all, ANSI standards say a Primary Key can not be NULL.


Good links to follow on NULL:
https://www.simple-talk.com/sql/t-sql-programming/how-to-get-nulls-horribly-wrong-in-sql-server/
http://sqlblog.com/blogs/hugo_kornelis/archive/2007/09/30/what-if-null-if-null-is-null-null-null-is-null.aspx


Other Related Question in series:
Can We Create Primary key with Clustered Index in SQL Server?
How to create a primary key without Clustered index?
Why SQL Server by default creates clustered index on the primary key?
Can we create a Primary key without clustered index?
Can we create primary key without any index?
Can we create primary key on more than one column?
Can we have a functinality of primary key without creating a primary key?
Why primary key doesn`t accepts null values?
What is the need of primary key?
Is it mandotary to have a primary key in the table?

We will try to answer all the above questions and link all of them to each other,
We welcome everybody to contribute to this question answer series.

Contact for Free SQL Server Performance Consulting and Training for you or your Organization.

Neerajprasadsharma, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response