SQL Server中的uniqueidentifier类型

uniqueidentifier类型可以配合T-SQL中的newid和newsequentialid来生成唯一标识符,具体区别如下(摘抄自微软官方文档)。

Nonsequential GUIDs: You can generate nonsequential global unique identifiers to be stored in an attribute of a UNIQUEIDENTIFIER type. You can use the T-SQL function NEWID to generate a new GUID, possibly invoking it with a default expression attached to the column. You can also generate one from anywhere. for example, the client by using an application programming interface (API) that generates a new GUID. The GUIDs are guaranteed to be unique across space and time.

Sequential GUIDs: You can generate sequential GUIDs within the machine by using the T-SQL function NEWSEQUENTIALID.

 

测试代码:

create table t_1(
id uniqueidentifier ROWGUIDCOL  primary key default NEWSEQUENTIALID(),
value int
)
create table t_2(
id uniqueidentifier ROWGUIDCOL  primary key default NEWID(),
value int
)

insert into t_1(value) values (1)
insert into t_1(value) values (2)
insert into t_1(value) values (3)
insert into t_1(value) values (4)
insert into t_1(value) values (5)

insert into t_2(value) values (1)
insert into t_2(value) values (2)
insert into t_2(value) values (3)
insert into t_2(value) values (4)
insert into t_2(value) values (5)

select *,rowguidcol from t_1
select *,rowguidcol from t_2

 

 

转载于:https://www.cnblogs.com/finalboss1987/p/5127565.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值