关于 GUID 的使用
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要全面了解 GUID 是什么,请查看我们的好朋友维基百科:GUID。
几乎可以保证是唯一的。在同一台机器上生成相同的两次的可能性非常小。可以说,在更广阔的世界中生成两个相同的 GUID 的机会很小,但这种机会仍然很小,而且这两个 GUID 相遇的机会也很小。事实上,大型强子对撞机产生吞噬地球的黑洞的可能性可能比在网络某处遇到两个相同的 GUID 的可能性更大。
正因为如此,有些人喜欢用它作为数据库表的主键。就我个人而言,我不喜欢这样做,因为:
如果您需要一个在多个不同区域(如注册表中的配置单元)中唯一的标识符,那么 GUID 是一个很好的解决方案。在这种特殊情况下,它们被用来识别类型。具体实例也可以在内部使用 GUID 标识符,但这实际上只对数据对象有用。
For a good overview of what a GUID is, check out our good friend Wikipedia: GUID.
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:
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.