本文介绍了增量GUID和唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#和SQL Server按顺序生成Guid

例如

00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000001
00000000-0000-0000-0000-000000000002
...................................
00000000-0000-0000-0000-00000000000F
00000000-0000-0000-0000-000000000010
.................
.............
4FF2EAFF-32BF-445D-8A61-2A9303828C2D

我需要能够在SQL Server中做到这一点(例如为int设置身份规范)
我需要像Guid.NextGuid()这样在C#中执行此操作,并且它会递增.

Thanx

I would like to generate Guids in Order using C# and SQL Server

Eg

00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000001
00000000-0000-0000-0000-000000000002
...................................
00000000-0000-0000-0000-00000000000F
00000000-0000-0000-0000-000000000010
.................
.............
4FF2EAFF-32BF-445D-8A61-2A9303828C2D

I need to be able to do this in SQL server (like setting identity spec for int)
and I need to do this in C# like Guid.NextGuid() and it increments.

Thanx

推荐答案

Create table Test (
    Key    bigint identity(-9223372036854775808, 1)
)



您可以使用十进制,这将允许-10e + 38到10e + 38



You could use decimal which would allows -10e+38 to 10e+38

create table Test (
    Key    test1 decimal(38,0) identity(-10000000000000000000000000000000000000,1)
)



这将为您提供2e + 38的值,这仍然比一个Guid所能达到的〜3.4e + 38值略短,但是如果您需要那么多,我会感到震惊.


2e + 38 = 2十亿= 20,000,000,000,000,000,000,000,000,000,000,000,000,000,000



That would give you 2e+38 values, which is still a little short of the ~3.4e+38 values you could have with a guid, but I''d be shocked if you need that many.


2e+38 = 2 Undecillion = 20,000,000,000,000,000,000,000,000,000,000,000,000



这篇关于增量GUID和唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 16:50