INT PRIMARY KEY 和 INTEGER PRIMARY KEY SQLite 的区别 [英] Difference between INT PRIMARY KEY and INTEGER PRIMARY KEY SQLite

查看:59
本文介绍了INT PRIMARY KEY 和 INTEGER PRIMARY KEY SQLite 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为表定义模式时,INT PRIMARY KEYINTEGER PRIMARY KEY 之间有什么区别吗?当使用 int 主键时,我生成了 sqlite_autoindex thing ;当整数主键时,我生成了 sqlite_sequence 表.有什么区别?第一种和第二种变体有哪些副作用?

Is there any difference between INT PRIMARY KEY and INTEGER PRIMARY KEY when defining a schema for a table? When int primary key is used, I got sqlite_autoindex thing generated; when integer primary key , I got sqlite_sequence table generated. what's the difference? what side effects can have the first and second variants?

推荐答案

是的,有区别:INTEGER 是 SQLite 中的一个特例,当数据库没有没有 创建一个单独的主键,但重用 ROWID 列.当您使用 INT(或在内部映射"到 INTEGER 的任何其他类型)时,会创建一个单独的主键.

Yes, there is a difference: INTEGER is a special case in SQLite, when the database does not create a separate primary key, but reuses the ROWID column instead. When you use INT (or any other type that "maps" to INTEGER internally) a separate primary key is created.

这就是为什么您会看到为 INT 主键创建了 sqlite_autoindex,而没有为 INTEGER 类型创建索引:SQLite 重用整数主键的内置索引结构,不需要自动索引.

That is why you see sqlite_autoindex created for the INT primary key, and no index created for the one of type INTEGER: SQLite reuses a built-in indexing structure for the integer primary key, rendering the autoindex unnecessary.

这就是为什么 INTEGER 主键在存储和性能方面都更经济的原因.

That is why the INTEGER primary key is more economical, both in terms of storage and in terms of performance.

请参阅此链接了解详情.

这篇关于INT PRIMARY KEY 和 INTEGER PRIMARY KEY SQLite 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆