正如我从其他讨论中理解的,一些RDBMS(例如sqlite,MysqL)在主键中允许“唯一”NULL.
为什么这是允许的,它可能如何有用?
背景:我认为有助于与同事和数据库专业人员沟通,了解不同DBMS中基本概念,方法及其实现的差异.
笔记
> MysqL被修复并返回到“NOT NULL PK”列表.
>已经添加了sqlite(感谢Paul Hadfield)到“NULL PK”列表:
For the purposes of determining the uniqueness of primary key values,NULL values are considered distinct from all other values,including other NULLs.
If an INSERT or UPDATE statement attempts to modify the table content so that two or more rows feature identical primary key values,it is a constraint violation. According to the sql standard,PRIMARY KEY should always imply NOT NULL. Unfortunately,due to a long-standing coding oversight,this is not the case in sqlite.
Unless the column is an INTEGER PRIMARY KEY sqlite allows NULL values in a PRIMARY KEY column. We could change sqlite to conform to the standard (and we might do so in the future),but by the time the oversight was discovered,sqlite was in such wide use that we feared breaking legacy code if we fixed the problem.
So for now we have chosen to continue allowing NULLs in PRIMARY KEY columns. Developers should be aware,however,that we may change sqlite to conform to the sql standard in future and should design new programs accordingly.
— 07001