关于 GUID 的使用

发布于 2024-11-15 19:19:02 字数 177 浏览 1 评论 0原文

Wiki说它用于使类、接口唯一标识符,那么对象(实际实例)呢?

使用SQL时,我还看到ID字段的GUID(asp.net MVC模板项目中的数据库aspnetdb中的表用户等)

所以我想清楚地了解GUID的用法,哪种情况应该使用它,是吗?真的很独特,

任何解释表示赞赏,

谢谢

Wiki said it used to make class,interface uniquely identifier , how about object (actual instance) ??

When work with SQL,i also see the GUID for ID field (table user,..etc in database aspnetdb in asp.net MVC template project)

So I want to clearly understand the GUID usage, which case should use it , and is it really unique ,

Any explain appreciated

thank

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

你曾走过我的故事 2024-11-22 19:19:02

要全面了解 GUID 是什么,请查看我们的好朋友维基百科:GUID

它真的很独特

几乎可以保证是唯一的。在同一台机器上生成相同的两次的可能性非常小。可以说,在更广阔的世界中生成两个相同的 GUID 的机会很小,但这种机会仍然很小,而且这两个 GUID 相遇的机会也很小。事实上,大型强子对撞机产生吞噬地球的黑洞的可能性可能比在网络某处遇到两个相同的 GUID 的可能性更大。

正因为如此,有些人喜欢用它作为数据库表的主键。就我个人而言,我不喜欢这样做,因为:

  • 自动递增整数给了我足够的唯一性,能够将其用作主键
  • GUID 是编写 SQL 查询时要处理的大量 PITA。

Wiki说它用来制作类、接口唯一标识符

如果您需要一个在多个不同区域(如注册表中的配置单元)中唯一的标识符,那么 GUID 是一个很好的解决方案。在这种特殊情况下,它们被用来识别类型。具体实例也可以在内部使用 GUID 标识符,但这实际上只对数据对象有用。

For a good overview of what a GUID is, check out our good friend Wikipedia: GUID.

and is it really unique

GUIDs generated from the same machine are virtually guaranteed to be unique. You have an infinitesimally small chance of generating the same one twice on the same machine. Arguably you have a tiny chance of generating two GUIDs the same out in the wider world, but that chance is still small and the chances of those two GUIDs ever meeting are also pretty small. In fact you probably have a greater chance of the Large Hadron Collider generating a black hole that swallows the Earth than you would having two identical GUIDs meeting somewhere on a network.

Because of this, some people like to use it as the primary key for database tables. Personally i don't like to do this because:

  • an auto-incrementing integer gives me enough uniqueness to be able to use it as a primary key
  • GUIDs are a massive PITA to deal with when you are writing SQL queries.

Wiki said it used to make class,interface uniquely identifier

If you need an identifier that is unique across several disparate areas (like hives in a registry), then GUIDs are a good solution. In this particular case they are being used to identify a type. A concrete instance could also internally use a GUID identifier, but this is really only useful for data objects.

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