正如我从其他讨论中理解的,一些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
解决方法
原文地址:https://www.jb51.cc/mssql/82884.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。