UniqueIdentifier 数据类型 和 GUID 生成函数
发布日期:2021-05-09 04:55:17 浏览次数:17 分类:博客文章

本文共 4844 字,大约阅读时间需要 16 分钟。

UniqueIdentifier ������������������������GUID���������������16Byte��� SQL Server���UniqueIdentifier���������16������������������������������������Binary(16)������������������������������������������������������xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx������������x���������16���������������������������������0-9���A-F���������������������������2���16���������������������������������������������UniqueIdentifier���������������������4B-2B-2B-2B-6B���������GUID���������������������������Server������������GUID������������������������SQL Server������GUID������������������������������������������������������������������

���SQL Server������UniqueIdentifier ���������������

  • ���������������������UniqueIdentifier���������������������������������
  • ������GUID������������ NewID()������������������������GUID���
  • NewSequentialID() ���������������������������Default���������������������������GUID���
  • ������������������������������������������������������������'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'���x���16���������������������������������0-9���A-F���
  • UniqueIdentifier ������������������������������������is null ��� is not null ������������������������NULL���
  • ���������RowGUIDCol���������������������$ROWGUID ������������RowGUIDCol���������UniqueIdentifier������

���������UniqueIdentifier ������������

1���������NewID() ���UniqueIdentifier���������������NewID() ���������������������GUID���������

declare @ui uniqueidentifierset @ui=newid()select @ui

2������������������������������������������������������xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx���

declare @ui uniqueidentifierset @ui='AA786048-44BB-E511-80E3-F8B156CF6E62'select @ui

������������UniqueIdentifier column

������UniqueIdentifier ���������������������������������������������������������������UniqueIdentifier���������Default������������������GUID���������������������

������������Default���������������NewID()������������������������������������������

CREATE TABLE dbo.myTable_Rand(    ColumnA uniqueidentifier DEFAULT NewID(),    ColumnB int,    columnC varchar(10))

1������������GUID

NewID()���������������GUID������������������������������������������������������������������������������������ever-increasing value������SQL Sever ������������������GUID������������GUID ���������������������NewID()������������GUID������clustered index key���������������������������������������������������������������������Page split ��������� IO ���������

���������clustered index key ���������������������increase������data type is narrow (narrow)���������unique���unique���������������������������static������NewID() ���������GUID������narrow,unique, static������������������increase���������������������������clustered index key���

2������������GUID

���������������������������������NewSequentialId() ���������GUID���������������������������GUID���������������GUID������������������������������������������������GUID���������������������ever-increasing value���������SQL Sever ���������������GUID������������GUID ������NewSequentialID()���������������������������Default���������������������NewSequentialID() ���������GUID������clustered index key���������Insert������������row ������������table������������������ page split���������������NewSequentialID()������clustered index key���

NewSequentialID()  Creates a GUID that is greater than any GUID previously generated by this function on a specified computer since Windows was started. After restarting Windows, the GUID can start again from a lower range, but is still globally unique. When a GUID column is used as a row identifier, using NEWSEQUENTIALID can be faster than using the NEWID function. This is because the NEWID function causes random activity and uses fewer cached data pages. Using NEWSEQUENTIALID also helps to completely fill the data and index pages.

NEWSEQUENTIALID() can only be used with DEFAULT constraints on table columns of type uniqueidentifier. You can use NEWSEQUENTIALID to generate GUIDs to reduce page splits and random IO at the leaf level of indexes. Each GUID generated by using NEWSEQUENTIALID is unique on that computer.

CREATE TABLE dbo.myTable (    ColumnA uniqueidentifier DEFAULT NEWSEQUENTIALID(), ColumnB int, columnC varchar(10)) insert into dbo.myTable(ColumnB,columnC)values(1,'a'),(2,'c')

������ROWGUIDCOL ������

ROWGUIDCOL ��������������������������������� UniqueIdentifier ������������������������������������RowGUIDCol��������������������� $ROWGUID ��������������� ���������������������������������RowGUIDCol��������������������������������������������� $ROWGUID ���������UniqueIdentifier������

CREATE TABLE dbo.myTable_RowGUIDCol(    ColumnA uniqueidentifier ROWGUIDCOL not null            constraint DF__myTable_RowGUIDCol_ColumnA DEFAULT NewID(),    ColumnB int,    columnC varchar(10))

������$ROWGUID������������������RowGUIDCol ���column

select $ROWGUIDfrom dbo.myTable_RowGUIDCol

 

���������������

上一篇:列属性:RowGUIDCol、Identity 和 not for replication
下一篇:索引调优 第二篇:碎片整理

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月19日 21时58分48秒