加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

关于sqlite中primary key可以输入null的说明

发布时间:2020-12-12 23:30:02 所属栏目:百科 来源:网络整理
导读:按照SQL标准,主键(PRIMARY KEY)应该暗含NOT NULL,不幸地是,在SQLite中,因为长久以来的编码疏忽,导致 主键可以是NULL的. 我们可以修改SQLite让它符合标准(我们应该在未来这么做),但是 SQLite使用得太广泛,如果修正这个问题,我们担心会搞坏一些旧有的代码. 所

按照SQL标准,主键(PRIMARY KEY)应该暗含NOT NULL,不幸地是,在SQLite中,因为长久以来的编码疏忽,导致 主键可以是NULL的. 我们可以修改SQLite让它符合标准(我们应该在未来这么做),但是 SQLite使用得太广泛,如果修正这个问题,我们担心会搞坏一些旧有的代码. 所以,创建不能为NULL的主键时,应该使用 PRIMARY KEY NOT NULL 会比较可靠 原文如下: According to the SQL standard,PRIMARY KEY should imply NOT NULL. Unfortunately,due to a long-standing coding oversight,this is not the case in SQLite. 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读