GUID 作为 SQLite 的唯一键
我找到了 使用 python 生成 GUID 例程。
运行代码给出以下结果。
GUID: 00000129e0e72d9b2aab3c1500ac001000e90001 Time: Sat, 17 Jul 2010 09:55:33 (millis: 0.787) IP: 172.16.233.1 Counter: 715865109
该代码的注释有以下消息。
### GUIDs make wonderful database keys. They require no access to the ### database (to get the max index number), they are extremely unique, and they sort ### automatically by time. GUIDs prevent key clashes when merging ### two databases together, combining data, or generating keys in distributed ### systems.
问题
- 这可以与 SQLite 一起使用吗?据我所知,SQLite中的INTEGER类型是8字节,并且使用8字节,不可能以十进制存储值0x00000129e0e72d9b2aab3c1500ac001000e90001或101362835865894089778560972572099193929729。
- 有什么方法可以使用 SQLite 获得全局唯一 ID 吗?
I found GUID generation routine with python.
Running the code gives me the following results.
GUID: 00000129e0e72d9b2aab3c1500ac001000e90001 Time: Sat, 17 Jul 2010 09:55:33 (millis: 0.787) IP: 172.16.233.1 Counter: 715865109
The comments of this code has the following message.
### GUIDs make wonderful database keys. They require no access to the ### database (to get the max index number), they are extremely unique, and they sort ### automatically by time. GUIDs prevent key clashes when merging ### two databases together, combining data, or generating keys in distributed ### systems.
Questions
- Does this work with SQLite? As far as I know INTEGER type in SQLite is 8 byte, and with 8 byte, it's not possible to store value 0x00000129e0e72d9b2aab3c1500ac001000e90001 or 101362835865894089778560972572099193929729 in decimal.
- Is there any way to get unique ID globally with SQLite?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了占用 32 个字节而不是 16 个字节之外,在 SQLite 中将 GUID 存储为文本有什么问题?
Other than the fact that it takes up 32 bytes instead of 16, what's wrong with storing a GUID as text in SQLite?
好文章可以帮助您做出决定...
主键:ID 与 GUID:
http://www.codinghorror.com/blog/2007/03/primary-keys-ids-versus-guids.html
Good article to help you get decision....
Primary Keys: IDs vs GUIDs:
http://www.codinghorror.com/blog/2007/03/primary-keys-ids-versus-guids.html
每个 SQLite 数据行都有一个 64 位本地唯一标识符。从表中选择 rowid...
Every SQLite data row has a 64 bit locally-unique identifier. SELECT rowid FROM table...