您的位置:首页 > 数据库

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

2011-02-25 10:49 127 查看
按照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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐