GUID到底是什么? 为什么以及在哪里应该使用它?

发布于 2024-07-10 14:37:00 字数 112 浏览 5 评论 0原文

GUID到底是什么? 为什么以及在哪里应该使用它?
我在很多地方都看到了对 GUID 的引用,在维基百科中, 但它并不太清楚告诉你在哪里使用它。 如果有人能回答这个问题,那就太好了。 谢谢

What exactly is GUID? Why and where I should use it?
I've seen references to GUID in a lot of places, and in wikipedia,
but it is not very clear telling you where to use it.
If someone could answer this, it would be nice.
Thanks

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

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

发布评论

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

评论(16

星星的轨迹 2024-07-17 14:37:00

GUID 从技术上来说代表全球唯一标识符。 实际上,它是一个 128 位结构,不可能重复或产生冲突。 如果您进行数学计算,值的域是十一亿

当您有多个独立系统或客户端生成需要唯一的 ID 时,请使用 guid。

例如,如果我有 5 个客户端应用程序创建事务数据并将其插入到对 ID 有唯一约束的表中,则使用 guid。 这可以避免强制客户端首先向服务器请求颁发的 ID。

这对于将大量对象类型存储在不同表中的对象工厂和系统也非常有用,您不希望任何 2 个对象具有相同的 ID。 这使得缓存和清理模式更容易实现。

GUID technically stands for globally unique identifier. What it is, actually, is a 128 bit structure that is unlikely to ever repeat or create a collision. If you do the maths, the domain of values is in the undecillions.

Use guids when you have multiple independent systems or clients generating ID's that need to be unique.

For example, if I have 5 client apps creating and inserting transactional data into a table that has a unique constraint on the ID, then use guids. This prevents having to force a client to request an issued ID from the server first.

This is also great for object factories and systems that have numerous object types stored in different tables where you don't want any 2 objects to have the same ID. This makes caching and scavenging schemas much easier to implement.

蓝天 2024-07-17 14:37:00

GUID 是“全球唯一标识符”。 您可以在需要保证与其他标识符不同的标识符的任何地方使用它。

通常,您只需要一个“本地唯一”的值 - 例如,数据库表中的主键标识只需与该表中的其他行不同,但可以与其他表中的 ID 相同。 (此处不需要 GUID)

当您定义的 ID 必须与其他人(在您的控制范围之外)定义的 ID 不同时,通常会使用 GUID。 ActiveX 控件上的接口标识符中的一个这样的位置。 任何人都可以创建 ActiveX,并且不知道其他人将使用它们的其他控件 --- 并且没有什么可以阻止每个人为他们的控件指定相同的名称。 GUID 使它们保持独特。

GUID 是时间(非常小的一秒)(因此它确保与之前或之后定义的任何 GUID 不同)和定义您的位置的数字(有时取自网卡的 MAC 地址)的组合。 (因此它肯定与其他人现在定义的任何其他 GUID 不同)。

它们有时也称为 UUID(通用唯一 ID)。

A GUID is a "Globally Unique IDentifier". You use it anywhere that you need an identifier that guaranteed to be different than every other.

Usually, you only need a value to be "locally unique" -- the Primary Key identity in a database table,for example, needs only be different from the other rows in that table, but can be the same as the ID in other tables. (no need for a GUID here)

GUIDs are generally used when you will be defining an ID that must be different from an ID that someone else (outside of your control) will be defining. One such place in the Interface identifier on ActiveX controls. Anyone can create an ActiveX, and not know with what other control someone will be using them with --- and there's nothing to stop everyone from giving their controls the same name. GUIDs keep them distinct.

GUIDs are a combination of the time (in very small fractions of a second) (so it assured to be different from any GUID defined before or later), and a number defining your location (sometimes taken from the MAC address of you network card) (so it's assured to be different from any other GUID defined right now by someone else).

They are also sometimes known as UUIDs (universally unique ID).

稚气少女 2024-07-17 14:37:00

除了所有其他答案之外,这里还有一个在线 GUID 生成器

http://www.guidgenerator.com/。 guidgenerator.com/

什么是 GUID?

GUID(或 UUID)是缩写
“全球唯一标识符”(或
“通用唯一标识符”)。 它
是一个 128 位整数,用于
识别资源。 术语 GUID 是
通常由开发人员使用
与微软技术,同时
UUID 在其他地方都使用。

GUID 有多独特?

128位已经足够大了
生成算法足够独特
如果每个 1,0000,000,000 个 GUID
第二个是 1 年生成的
重复的概率是
只有50%。 或者如果地球上的每个人
在那里生成了 600,000,000 个 GUID
只有 50% 的概率
重复。

如何使用 GUID?

GUID 用于软件开发
作为数据库键、组件
标识符,或任何地方
否则一个真正唯一的标识符是
必需的。 GUID 还用于
识别所有接口和对象
COM 编程。

As addition to all the other answers, here is an online GUID generator:

http://www.guidgenerator.com/

What is a GUID?

GUID (or UUID) is an acronym for
'Globally Unique Identifier' (or
'Universally Unique Identifier'). It
is a 128-bit integer number used to
identify resources. The term GUID is
generally used by developers working
with Microsoft technologies, while
UUID is used everywhere else.

How unique is a GUID?

128-bits is big enough and the
generation algorithm is unique enough
that if 1,0000,000,000 GUIDs per
second were generated for 1 year the
probability of a duplicate would be
only 50%. Or if every human on Earth
generated 600,000,000 GUIDs there
would only be a 50% probability of a
duplicate.

How are GUIDs used?

GUIDs are used in software development
as database keys, component
identifiers, or just about anywhere
else a truly unique identifier is
required. GUIDs are also used to
identify all interfaces and objects in
COM programming.

与往事干杯 2024-07-17 14:37:00

GUID 是“全局唯一 ID”。 也称为 UUID(通用唯一 ID)。

它基本上是一个以某种方式生成的 128 位数字(请参阅 RFC 4112 http://www.ietf .org/rfc/rfc4122.txt),这使得几乎不可能生成重复项。 这样,我就可以生成 GUID,而无需第三方组织将它们提供给我以确保它们是唯一的。

GUID 的一种广泛用途是用作 Windows 上 COM 实体(类、类型库、接口等)的标识符。 使用 GUID,开发人员可以构建他们的 COM 组件,而无需向 Microsoft 获取唯一标识符。 尽管识别 COM 实体是 GUID 的主要用途,但它们也用于许多需要唯一标识符的事情。 一些开发人员将为数据库记录生成 GUID,以便为它们提供一个可以使用的 ID,即使它们在许多不同的数据库中必须是唯一的。

一般来说,您可以将 GUID 视为任何人都可以随时生成的序列号,并且他们会知道该序列号是唯一的。

获取唯一标识符的其他方法包括获取域名。 为了确保域名的唯一性,您必须从某个组织(最终由 ICANN 管理)获取域名。

由于 GUID 可能很笨重(从人类可读的角度来看,它们是一串十六进制数字,通常按如下方式分组:aaaaaaaa-bbbb-cccc-dddd-ffffffffffff),因此一些需要在不同组织中具有唯一名称的命名空间使用另一种方案(通常基于互联网域名)。

因此,按照惯例,Java 包的命名空间以组织的域名(反转)开头,后跟以某种组织特定方式确定的名称。 例如,Java 包可能被命名为:

com.example.jpackage

这意味着处理名称冲突成为每个组织的责任。

XML 命名空间也以类似的方式变得唯一 - 按照惯例,创建 XML 命名空间的人应该将其置于其控制下的注册域名“下方”。 例如:

xmlns="http://www.w3.org/1999/xhtml"

管理唯一 ID 的另一种方法是以太网 MAC 地址。 制造以太网卡的公司必须获得 IEEE(我认为是 IEEE)分配给它们的地址块。 在这种情况下,该方案效果很好,即使制造商搞砸了并发行了具有重复 MAC 地址的卡,只要这些卡不在同一子网上,事情仍然可以正常进行,因为在子网之外,只有 IP地址用于路由数据包。 尽管 MAC 地址的其他一些用途可能会受到影响,但生成 GUID 的算法之一使用 MAC 地址作为参数之一。 这种 GUID 生成方法不再广泛使用,因为它被认为是一种隐私威胁。

Microsoft 为 Windows 9x 中的“VxD”驱动程序提供的 ID 是一种效果不佳的唯一标识符方案示例。 第三方 VxD 驱动程序的开发人员应该向 Microsoft 请求一组 ID,以用于第三方编写的任何驱动程序。 这样,微软就可以确保不存在重复的 ID。 不幸的是,许多驱动程序编写者从不打扰,只是使用他们用作起点的示例 VxD 中的任何 ID。 我不确定这会造成多少麻烦 - 我不认为 VxD ID 唯一性是绝对必要的,但它可能会影响某些 API 中的某些功能。

A GUID is a "Globally Unique ID". Also called a UUID (Universally Unique ID).

It's basically a 128 bit number that is generated in a way (see RFC 4112 http://www.ietf.org/rfc/rfc4122.txt) that makes it nearly impossible for duplicates to be generated. This way, I can generate GUIDs without some third party organization having to give them to me to ensure they are unique.

One widespread use of GUIDs is as identifiers for COM entities on Windows (classes, typelibs, interfaces, etc.). Using GUIDs, developers could build their COM components without going to Microsoft to get a unique identifier. Even though identifying COM entities is a major use of GUIDs, they are used for many things that need unique identifiers. Some developers will generate GUIDs for database records to provide them an ID that can be used even when they must be unique across many different databases.

Generally, you can think of a GUID as a serial number that can be generated by anyone at anytime and they'll know that the serial number will be unique.

Other ways to get unique identifiers include getting a domain name. To ensure the uniqueness of domain names, you have to get it from some organization (ultimately administered by ICANN).

Because GUIDs can be unwieldy (from a human readable point of view they are a string of hexadecimal numbers, usually grouped like so: aaaaaaaa-bbbb-cccc-dddd-ffffffffffff), some namespaces that need unique names across different organization use another scheme (often based on Internet domain names).

So, the namespace for Java packages by convention starts with the orgnaization's domain name (reversed) followed by names that are determined in some organization specfic way. For example, a Java package might be named:

com.example.jpackage

This means that dealing with name collisions becomes the responsibility of each organization.

XML namespaces are also made unique in a similar way - by convention, someone creating an XML namespace is supposed to make it 'underneath' a registered domain name under their control. For example:

xmlns="http://www.w3.org/1999/xhtml"

Another way that unique IDs have been managed is for Ethernet MAC addresses. A company that makes Ethernet cards has to get a block of addresses assigned to them by the IEEE (I think it's the IEEE). In this case the scheme has worked pretty well, and even if a manufacturer screws up and issues cards with duplicate MAC addresses, things will still work OK as long as those cards are not on the same subnet, since beyond a subnet, only the IP address is used to route packets. Although there are some other uses of MAC addresses that might be affected - one of the algorithms for generating GUIDs uses the MAC address as one parameter. This GUID generation method is not as widely used anymore because it is considered a privacy threat.

One example of a scheme to come up with unique identifiers that didn't work very well was the Microsoft provided ID's for 'VxD' drivers in Windows 9x. Developers of third party VxD drivers were supposed to ask Microsoft for a set of IDs to use for any drivers the third party wrote. This way, Microsoft could ensure there were not duplicate IDs. Unfortunately, many driver writers never bothered, and simply used whatever ID was in the example VxD they used as a starting point. I'm not sure how much trouble this caused - I don't think VxD ID uniqueness was absolutely necessary, but it probably affected some functionality in some APIs.

入画浅相思 2024-07-17 14:37:00

GUID 或 UUID(全局 vs 通用)唯一标识符是唯一的 ID :) 当您需要真正由机器生成的东西时,有一些库可以为您提供一个。

有关详细信息,请参阅维基百科上的 GUID

至于何时不需要 GUID,是指当您控制的计数器(以某种方式,如 SERIAL SQL 类型或序列)递增时。 索引“文本”值(文本形式的 GUID)或 128 位二进制值(GUID 就是)比整数昂贵得多。

GUID or UUID (globally vs Universally) Unique IDentifier is, well, a unique ID :) When you need something really unique machine generated, there are libraries to get you one.

See GUID on wikipedia for details.

As to when you don't need a GUID, it is when a counter that you control (one way or another, like a SERIAL SQL type or a sequence) gets incremented. Indexing a "text" value (GUID in textual form) or a 128 bit binary value (which a GUID is) is far more expensive than an integer.

我的痛♀有谁懂 2024-07-17 14:37:00

对我来说,更容易将它们视为简单的“128 位随机值”。 这本质上就是它们。 有一些算法可以在 GUID 的几位数字中包含一些信息(因此随机部分会变小),但它们仍然是相当大的几乎随机值。

由于它们太大,因此不可能生成两个相同的 GUID。 出于所有实际目的,生成的每个 GUID 在世界上都是唯一的。

我将让您弄清楚在哪里使用它们,但其他答案已经有一些示例。 让想象力自由驰骋。 :)

For me it's easier to think of them as simply "128-bit random values". Which is essentially what they are. There are some algorithms for including a bit of information in a few digits of your GUID (thus the random part gets a bit smaller), but still they are pretty large almost-random values.

Since they are so large, it is extremely unlikely that two GUIDs will ever be generated that are the same. For all practical purposes, every GUID ever generated is unique in the world.

I'll leave it to you to figure out where to use them, but other answers already have some examples. Let your imagination run wild. :)

-柠檬树下少年和吉他 2024-07-17 14:37:00

有人说它们在概念上是 128 位随机值,这基本上是正确的,但在 UUID 上做了一些阅读(GUID通常是指微软对UUID的实现),我看到有几个不同的UUID版本,而且大多数实际上并不是随机的。 因此,可以为机器(或其他设备)生成 UUID,并能够可靠地重复该过程以获取相同的 UUID,这对于某些应用程序非常重要。

Someone said they are conceptually 128-bit random values, and that is substantially true, but having done a little reading on UUID (GUID usually refers to Microsoft's implementation of UUID), I see that there are several different UUID versions, and most of them are not actually random. So it is possible to generate a UUID for a machine (or something else) and be able to reliably repeat that process to obtain the same UUID down the road, which is important for some applications.

假扮的天使 2024-07-17 14:37:00

这可能是一件很难理解的事情,因为生成它们背后需要进行所有的数学运算。 将其视为唯一的 ID。 您可以让 Visual Studio 为您生成一个,或者如果您碰巧使用 C# 或许多其他应用程序或网站之一,则可以使用 .NET。 它们被认为是独一无二的,因为你会看到同一个东西两次的可能性很小,所以不值得考虑。

Can be a hard thing to understand because of all the maths that goes on behind generating them. Think of it as a unique id. You can get Visual Studio to generate one for you, or .NET if you happen to be using C# or one of the many other applications or websites. They are considered unique because there is such a silly small chance you'll see the same one twice that it isn't worth considering.

Oo萌小芽oO 2024-07-17 14:37:00

128 位全局唯一 ID。 从现在到日落,您都可以生成 GUID,并且您永远不会两次生成相同的 GUID,其他人也不会。 它们经常与 COM 一起使用。

例如,我们将它们用于我们的一款产品中。 我们的用户可以在各种设备上生成类别和卡片。 我们希望确保不会将一台设备上创建的类别与另一台设备上创建的类别混淆,因此无论由谁生成、在何处生成以及何时生成,ID 都是唯一的,这一点很重要。 所以我们使用 GUID(实际上我们使用我们自己的方案,使用 64 位数字,但它们与 GUID 类似)。

128-bit Globally Unique ID. You can generate GUIDs from now until sunset and you never generate the same GUID twice, and neither will anyone else. They are used a lot with COM.

As for example of something you would use them for, we use them in one of our products. Our users can generate categories and cards on various devices. We want to make sure that we don't confuse a category made on one device with a category created on a different one, so it's important that IDs are unique no matter who generates them, where they generate them, and when they generate them. So we use GUIDs (actually we use our own scheme using 64-bit numbers but they are similar to GUIDs).

旧人哭 2024-07-17 14:37:00

几年前,我在 ACD 呼叫中心系统上工作,我们希望将来自多个呼叫处理器的呼叫详细记录收集到一个数据库中。 我在 MS SQL 中设置一列来为数据库密钥生成 GUID,而不是使用系统生成的顺序 ID (身份栏)。 当时,这需要将默认值设置为 NewID(或在代码中生成它,但 NewID() 函数更安全)。 当然,拥有较大的密钥值可能会引起一些人的注意,但我宁愿放弃空间也不愿冒碰撞的风险。

我没有看到任何人使用 GUID 作为数据库密钥,因此我认为知道您也可以这样做可能会有所帮助。

I worked on an ACD call center system a few years back where we wanted to gather call detail records from multiple call processors into a single database. I setup a column in MS SQL to generate a GUID for the database key rather than using a system-generated sequential ID (identity column). Back then, this required setting the default value to NewID (or generating it in the code, but the NewID() function was safer). Of course, having a large value for a key may raise a few eyebrows, but I would rather give up the space than risk a collision.

I didn't see anyone address using a GUID as a database key so I thought it might help to know you could do that too.

爱,才寂寞 2024-07-17 14:37:00

GUID 代表“全球唯一标识符”,当您想要拥有全球唯一标识符时,您可以使用它。

例如,在 RSS 源中,源中的每个项目都应该有一个 GUID。 这样,提要阅读器软件就可以跟踪您是否已阅读该项目。 如果没有 GUID,就无法辨别。

GUID 与数据库 ID 之类的东西不同,因为无论谁创建对象(你、我、街上的那个人),我们的 GUID总是都会不同。 使用 GUID 不应发生冲突。

您还会看到术语 UUID,它代表“通用唯一标识符”。 两者本质上没有区别。 UUID 是更合适的术语。 GUID 是 Microsoft 使用的术语。

GUID stands for "Globally Unique Identifier" and you use it when you want to have, erm, a Globally Unique Identifier.

In RSS feeds, for example, you should have a GUID for each item in the feed. That way, the feed reader software can keep track of whether you have read that item or not. Without a GUID, it would be impossible to tell.

A GUID differs from something like a database ID in that no matter who creates an object -- you, me, the guy down the street -- our GUIDs will always be different. There should be no collisions using a GUID.

You'll also see the term UUID, which stands for "Universally Unique Identifier." There is essentially no difference between the two. UUID is the more appropriate term. GUID is the term used by Microsoft.

朕就是辣么酷 2024-07-17 14:37:00

如果您需要生成在应用程序的整个生命周期内保持唯一的标识符,则可以使用 GUID。

想象一下,您有一台带有会话的服务器,如果您为每个会话提供一个 GUID,那么您可以确定它对于您的服务器创建的每个会话都是唯一的。 这对于跟踪错误很有用。

If you need to generate an identifier that needs to be unique during the whole lifetime of your application, you use a GUID.

Imagine you have a server with sessions, if you give each session a GUID, you are certain that it will be unique for every session ever created by your server. This is useful for tracing bugs.

廻憶裏菂餘溫 2024-07-17 14:37:00

我发现 GUID 的一个特别有用的应用是使用它们来跟踪 Web 应用程序中的唯一访问者,其中访问者是匿名的(即未登录或注册)。

One particularly useful application of GUIDs that I've found is using them to track unique visitors in webapps where the visitors are anonymous (i.e. not logged in or registered).

羁〃客ぐ 2024-07-17 14:37:00

GUID = 全局唯一标识符。

当您想要在全局上下文中唯一标识某些内容时,请使用它。

这个生成器可以很方便。

GUID = Global Unique IDentifier.

Use it when you want to uniquely identify something in a global context.

This generator can be handy.

浅语花开 2024-07-17 14:37:00

关于 GUID 的 Wikipedia 文章非常清楚它们的用途 - 也许改写你的问题会帮助 - 您需要 GUID 做什么?

The Wikipedia article on GUIDs is pretty clear on what they are used for - maybe rephrasing your question would help - what do you need a GUID for?

云巢 2024-07-17 14:37:00

要实际查看它在 Windows 计算机上的样子,请转到 cmd 或 powershell。

  1. Powershell =>; [guid]::NewGuid()

  2. CMD => powershell [guid]::NewGuid()

在此处输入图像描述

To actually see what it looks like on a windows computer, go to cmd or powershell.

  1. Powershell => [guid]::NewGuid()

  2. CMD => powershell [guid]::NewGuid()

enter image description here

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