SQL Server 如何使用 NEWID() 创建唯一标识符 [英] How SQL Server creates uniqueidentifier using NEWID()

查看:54
本文介绍了SQL Server 如何使用 NEWID() 创建唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在五个不同的位置有一个 user_info 表.现在我需要将所有行集成到一个中央 user_info 表中.为此,我需要源表中每一行的唯一 ID.因为当所有的行都进入中央表时,那么每个用户都必须有一个唯一的 ID.

I have a user_info table in five different locations. Now I need to integrate all the rows into a central user_info table. To do this I need a unique id for each row in source tables. Because when all the rows come into the central table, then each user must have a unique ID.

现在我的问题是:

  1. 如果我对每个源表使用 uniqueidentifier NEWID() 那么它对于全局来说是唯一的吗?生命的时间还是有机会被复制?

  1. if I use uniqueidentifier NEWID() for each source table then is it will be unique for globally & life time or have any chance to be duplicate?

SQL Server 如何创建NEWID()?我需要知道密钥生成结构.

How does SQL Server create the NEWID()? I need to know the key generation structure.

推荐答案

是的,机器之间不可能有重复.

Yes, there is no chance of a duplicate between machines.

NEWID() 基于伪随机数(来自时钟)和主 NIC 的 MAC 地址的组合.

NEWID() is based on a combination of a pseudo random number (from the clock) and the MAC address of the primary NIC.

然而,像这样插入随机数作为表上的聚集键对性能来说是很糟糕的.您应该考虑使用 NEWSEQUENTIALID() 或 COMB 类型的函数来生成 GUID,这些函数仍提供 NEWID() 的冲突避免优势,同时仍保持可接受的 INSERT 性能.

However, inserting random numbers like this as the clustered key on a table is terrible for performance. You should consider either NEWSEQUENTIALID() or a COMB-type function for generating GUIDs that still offer the collision-avoidance benefits of NEWID() while still maintaining acceptable INSERT performance.

这篇关于SQL Server 如何使用 NEWID() 创建唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆