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

INT PRIMARY KEY和INTEGER主键之间的区别SQLite

发布时间:2020-12-12 19:11:24 所属栏目:百科 来源:网络整理
导读:在定义表的模式时,INT PRIMARY KEY和INTEGER PRIMARY KEY之间是否有区别? 当使用int主键时,我生成了sqlite_autoindex事件; 当整数主键,我得到sqlite_sequence表生成. 有什么不同?什么副作用可以有第一和第二种变体? 全部解释 in the SQLite documentation
在定义表的模式时,INT PRIMARY KEY和INTEGER PRIMARY KEY之间是否有区别?
当使用int主键时,我生成了sqlite_autoindex事件;
当整数主键,我得到sqlite_sequence表生成.
有什么不同?什么副作用可以有第一和第二种变体? 全部解释 in the SQLite documentation:

2.0 The INTEGER PRIMARY KEY

One exception to the typelessness of SQLite is a column whose type is INTEGER PRIMARY KEY. (And you must use “INTEGER” not “INT”. A column of type INT PRIMARY KEY is typeless just like any other.) INTEGER PRIMARY KEY columns must contain a 32-bit signed integer. Any attempt to insert non-integer data will result in an error.

INTEGER PRIMARY KEY columns can be used to implement the equivalent of AUTOINCREMENT. If you try to insert a NULL into an INTEGER PRIMARY KEY column,the column will actually be filled with an integer that is one greater than the largest key already in the table. Or if the largest key is 2147483647,then the column will be filled with a random integer. Either way,the INTEGER PRIMARY KEY column will be assigned a unique integer. You can retrieve this integer using the sqlite_last_insert_rowid() API function or using the last_insert_rowid() SQL function in a subsequent SELECT statement.

(编辑:李大同)

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

    推荐文章
      热点阅读