GUID 作为 SQLite 的唯一键

发布于 2024-09-10 15:06:37 字数 876 浏览 1 评论 0原文

我找到了 使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故乡的云 2024-09-17 15:06:37

除了占用 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?

难忘№最初的完美 2024-09-17 15:06:37

好文章可以帮助您做出决定...

主键: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

如歌彻婉言 2024-09-17 15:06:37

每个 SQLite 数据行都有一个 64 位本地唯一标识符。从表中选择 rowid...

Every SQLite data row has a 64 bit locally-unique identifier. SELECT rowid FROM table...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文