Why Primary key cannot contain NULL values?

Why Primary key cannot contain NULL values?

I am sure you have heard this question a lot of time and probably you know the reason behind that but here are many professional who doesn't know the actual reason behind this. However, I am sure that after this article they would have a clear understanding about this question.

There is a rule in database designing which is known as Entity Integrity. So, basically this is the only reason because of which a Primary key should have unique records and cannot contain a null value.

For further reading, please read below mentioned explanation:

Entity Integrity ensures that there are no duplicate records within the table and that the field that identifies each record within the table is unique and never null.

The existence of the Primary Key is the core of the entity integrity. If you define a primary key for each entity, they follow the entity integrity rule.

Entity integrity specifies that the Primary Keys on every instance of an entity must be kept, must be unique and must have values other than NULL.

Although most relational databases do not specifically dictate that a table needs to have a Primary Key, it is good practice to design a Primary Key for each table in the relational model. This mandates no NULL content, so that every row in a table must have a value that denotes the row as a unique element of the entity.

Entity Integrity is the mechanism the system provides to maintain primary keys. The primary key serves as a unique identifier for rows in the table. Entity Integrity ensures two properties for primary keys:

  1.  The primary key for a row is unique; it does not match the primary key of any other row in the table.
  2. The primary key is not null, no component of the primary key may be set to null.

The uniqueness property ensures that the primary key of each row uniquely identifies it; there are no duplicates. The second property ensures that the primary key has meaning, has a value; no component of the key is missing.

The system enforces Entity Integrity by not allowing operations (INSERT, UPDATE) to produce an invalid primary key. Any operation that creates a duplicate primary key or one containing nulls is rejected.


John Basha

9x Microsoft Certified | Fabric Super User | Power BI Developer, Architect??? ?? | DAX | MSBI | T-SQL | Azure SQL, Data bricks, Synapse ?, Data Factory | Tabular SSAS | SSRS | SAP Hana | ?? Data Story teller ???

5 年

Nice Article Ajay

要查看或添加评论,请登录

Ajay Kumar的更多文章

  • Azure Data Lake Storage: The Ultimate Solution for Big Data Storage and Analytics

    Azure Data Lake Storage: The Ultimate Solution for Big Data Storage and Analytics

    As organizations generate more data, the need for scalable and flexible storage solutions becomes more pressing. Azure…

  • Power BI Best Practices

    Power BI Best Practices

    Dear all Power BI Users, In our day to day work we do design reports/share and publish them. No matter what, we always…

  • The valued competencies of Microsoft Power BI tool

    The valued competencies of Microsoft Power BI tool

    Power BI is a cloud-based business analytic solution, which is used to analyze data from a wide range of data sources…

  • Top 11 Best Practices of Power BI

    Top 11 Best Practices of Power BI

    Hello Power BI Users! Today, in this article, I am going to discuss about top 11 best practices in Power BI. I hope you…

    1 条评论
  • Power BI Data Gateway

    Power BI Data Gateway

    Hello Power BI Users, Lately, I came across a questions ..

  • Export Data From Power BI Dataset

    Export Data From Power BI Dataset

    Dear All, Most of times, I came across a question that how to extract any number of rows data from Power BI dataset…

    1 条评论
  • Power BI - Auto Recovery

    Power BI - Auto Recovery

    Many times, it happens that a Power BI user is working on a Power BI report/file and suddenly system crashed out or…

    1 条评论
  • Why Power BI Premium?

    Why Power BI Premium?

    Microsoft introduced Power BI in late 2013 as a separate software and since then it's continuously growing and now it's…

  • #1 Data Visualization & Analytics Tool

    #1 Data Visualization & Analytics Tool

    Good news for all Power BI Developers/Users. Once again, #Gartner named, Power BI as #1 Data Visualization & Analytics…

  • History of Ms Power BI

    History of Ms Power BI

    Everyone of us who all are working on Ms Power BI, must have idea about Power BI and what does it do but only few are…

社区洞察