DotNet Framework中连续生成GUID [英] Consecutive GUID Generation in DotNet Framework

查看:151
本文介绍了DotNet Framework中连续生成GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Current Framework 2.0 / 3.0。


...

在Sql Server中,有一种方法可以生成连续的guid'' s。

newsequentialid。


有没有办法在

框架中重现这种类型的连续guid'。


我找到了一些关于uuidgen的信息,但这似乎是命令行提示

工具,而不是类库。


我希望能够在它上面输入一个int值(N),然后返回N

连续guid'。

。 ........

这是我写的一个测试存储过程,告诉你我在说什么。



如果EXISTS(SELECT * FROM sys.objects WHERE object_id =

OBJECT_ID(N''[dbo]。[uspNewSequentialUUIDCreateRange]'')并键入(N''P'',

N''PC''))


DROP PROCEDURE [dbo]。[uspNewSequentialUUIDCreateRange]


GO


CREATE PROCEDURE [dbo]。[u spNewSequentialUUIDCreateRange](


@newUUIDCount int --return





AS


设置NOCOUNT


声明@t表(dummyid int,entryid int identity(1,1),uuid

uniqueidentifier默认newsequentialid())


插入@t(dummyid)从dbo.sysobjects中选择顶部(@newUUIDCount)0

所以使用(nolock)


选择entryid,uuid来自@t


SET NOCOUNT OFF


GO



/ *


--START测试


set nocount ON


创建表#HolderTable(entryid int,uuid uniqueidentifier)


声明@NewUUIDCount int


选择@NewUUIDCount = 20


INSERT INTO #HolderTable EXEC dbo.uspNewSequentialUUIDCreateRange

@NewUUIDCount


select * from #HolderTable


DROP表#HolderTable


--END测试代码


* /

解决方案

System.Guid.NewGuid()


-

John Saunders | MVP - 连接系统开发人员


只需使用最适合您需求的构造函数:
http://msdn.microsoft.com/en-us/libr...guid.guid.aspx


-

Patrice


" sloan" < sl *** @ipass.netaécritdansle message de groupe de discussion:
uf ************** @ TK2MSFTNGP05.phx.gbl ...


Current Framework 2.0 /3.0。


..


在Sql Server中,有一种方法可以生成连续的guid'。

newsequentialid。


有没有办法在

框架中重现这种类型的连续guid'。

我找到了一些关于uuidgen的信息,但这似乎是一个命令行

提示工具,而不是类库。


我''我希望能够在它上面输入一个int值(N),然后返回N

连续guid'。


.... ....


这是我写的一个测试存储过程,向你展示我在说什么

约。



如果EXISTS(SELECT * FROM sys.objects WHERE object_id =

OBJECT_ID(N') [dbo]。[uspNewSequentialUUIDCreateRange]'')输入(N''P'',

N''PC''))


DROP程序[dbo]。[uspNewSequentialUUIDCreateRange]


GO


CREATE PROCEDURE [dbo]。[uspNewSequentialUUIDCreateRange](

@newUUIDCount int - 返回





AS


SET NOCOUNT ON


声明@t表(dummyid int,entryid int identity(1,1),uuid

uniqueidentifier默认newsequentialid())


插入@t(dummyid)选择顶部(@newUUIDCount)0来自

dbo.sysobjects所以用(nolock)


选择entryid,uuid来自@t


SET NOCOUNT OFF


GO




/ *


--START测试


设置nocount ON


创建表#HolderTable(entryid int,uuid uniqueidentifier)


声明@NewUUIDCount int


select @Ne wUUIDCount = 20


INSERT INTO #HolderTable EXEC dbo.uspNewSequentialUUIDCreateRange

@NewUUIDCount


select * from #HolderTable


DROP表#HolderTable


--END测试代码


* /


我没有看到使用System.Guid类的方法。 newsequentialid被引入以提供SQL中的一些优化,但这不是GUID的

意图的一部分。 GUID有点随机,newsequentialid随机性消失了



" sloan"写道:


当前框架2.0 / 3.0。


...


在Sql Server中,有一种方法可以生成连续的guid'。

newsequentialid。


有没有办法重现这种类型的连续guid在

框架中。


我找到了一些关于uuidgen的信息,但这似乎是一个命令行提示

工具,而不是类库。


我希望能够在它上面输入一个int值(N),它返回N

连续guid'。


.........


这是我写给你的测试存储过程我正在谈论的是什么。



如果EXISTS(SELECT * FROM sys.objects WHERE object_id =

OBJECT_ID( N''[dbo]。[uspNewSequentialUUIDCreateRange]'')输入(N''P'',

N''PC''))


DROP PROCEDURE [dbo]。[uspNewSequentialUUIDCreateRange]


GO


CREATE PROCEDURE [dbo]。[uspNewSequentialUUIDCreateRange](


@newUUIDCount int - 返回





AS


设为NOCOUNT ON


声明@t表(dummyid int,entryid int identity(1,1),uuid

uniqueidentifier默认newsequentialid())


插入@t(dummyid)从dbo.sysobjects中选择顶部(@newUUIDCount)0

所以用(nolock)


选择entryid,uuid来自@t


设定NOCOUNT OFF


GO



/ *


--START测试


设置nocount ON


创建表#HolderTable(entryid int ,uuid uniqueidentifier)


声明@NewUUIDCount int


选择@NewUUIDCount = 20


INSERT INTO #HolderTable EXEC dbo.uspNewSequentialUUIDCreateRange

@NewUUIDCount


select * from #HolderTable


DROP表#HolderTable


--END测试代码


* /


Current Framework 2.0/3.0.

...

In Sql Server, there is a way to generate consecutive guid''s.
newsequentialid.

Is there a way to reproduce this type of consecutive guid''s in the
framework.

I found some info about uuidgen , but that seems like a command line prompt
tool, not a class library.

I''d like to be able to throw an int value (N) at it, and it return N
consecutive guid''s.
.........
Here is a test stored procedure I wrote to show you what I''m talking about.


IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N''[dbo].[uspNewSequentialUUIDCreateRange]'') AND type in (N''P'',
N''PC''))

DROP PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange]

GO

CREATE PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange] (

@newUUIDCount int --return

)

AS

SET NOCOUNT ON

declare @t table ( dummyid int , entryid int identity(1,1) , uuid
uniqueidentifier default newsequentialid() )

insert into @t ( dummyid ) select top (@newUUIDCount) 0 from dbo.sysobjects
so with (nolock)

select entryid , uuid from @t

SET NOCOUNT OFF

GO



/*

--START TEST

set nocount ON

Create Table #HolderTable (entryid int , uuid uniqueidentifier )

declare @NewUUIDCount int

select @NewUUIDCount = 20

INSERT INTO #HolderTable EXEC dbo.uspNewSequentialUUIDCreateRange
@NewUUIDCount

select * from #HolderTable

DROP Table #HolderTable

--END TEST CODE

*/

解决方案

System.Guid.NewGuid()

--
John Saunders | MVP - Connected System Developer


Just use whatever constructor best fit your needs :
http://msdn.microsoft.com/en-us/libr...guid.guid.aspx

--
Patrice

"sloan" <sl***@ipass.neta écrit dans le message de groupe de discussion :
uf**************@TK2MSFTNGP05.phx.gbl...

Current Framework 2.0/3.0.

..

In Sql Server, there is a way to generate consecutive guid''s.
newsequentialid.

Is there a way to reproduce this type of consecutive guid''s in the
framework.

I found some info about uuidgen , but that seems like a command line
prompt tool, not a class library.

I''d like to be able to throw an int value (N) at it, and it return N
consecutive guid''s.
........
Here is a test stored procedure I wrote to show you what I''m talking
about.


IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N''[dbo].[uspNewSequentialUUIDCreateRange]'') AND type in (N''P'',
N''PC''))

DROP PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange]

GO

CREATE PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange] (

@newUUIDCount int --return

)

AS

SET NOCOUNT ON

declare @t table ( dummyid int , entryid int identity(1,1) , uuid
uniqueidentifier default newsequentialid() )

insert into @t ( dummyid ) select top (@newUUIDCount) 0 from
dbo.sysobjects so with (nolock)

select entryid , uuid from @t

SET NOCOUNT OFF

GO



/*

--START TEST

set nocount ON

Create Table #HolderTable (entryid int , uuid uniqueidentifier )

declare @NewUUIDCount int

select @NewUUIDCount = 20

INSERT INTO #HolderTable EXEC dbo.uspNewSequentialUUIDCreateRange
@NewUUIDCount

select * from #HolderTable

DROP Table #HolderTable

--END TEST CODE

*/


I don''t see a way to do this with the System.Guid class. newsequentialid was
introduced to provide some optimization in SQL, but that was not part of the
intent of GUIDs. GUIDs are somewhat random, and newsequentialid does away
with the randomness.
"sloan" wrote:

Current Framework 2.0/3.0.

...

In Sql Server, there is a way to generate consecutive guid''s.
newsequentialid.

Is there a way to reproduce this type of consecutive guid''s in the
framework.

I found some info about uuidgen , but that seems like a command line prompt
tool, not a class library.

I''d like to be able to throw an int value (N) at it, and it return N
consecutive guid''s.
.........
Here is a test stored procedure I wrote to show you what I''m talking about.


IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
OBJECT_ID(N''[dbo].[uspNewSequentialUUIDCreateRange]'') AND type in (N''P'',
N''PC''))

DROP PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange]

GO

CREATE PROCEDURE [dbo].[uspNewSequentialUUIDCreateRange] (

@newUUIDCount int --return

)

AS

SET NOCOUNT ON

declare @t table ( dummyid int , entryid int identity(1,1) , uuid
uniqueidentifier default newsequentialid() )

insert into @t ( dummyid ) select top (@newUUIDCount) 0 from dbo.sysobjects
so with (nolock)

select entryid , uuid from @t

SET NOCOUNT OFF

GO



/*

--START TEST

set nocount ON

Create Table #HolderTable (entryid int , uuid uniqueidentifier )

declare @NewUUIDCount int

select @NewUUIDCount = 20

INSERT INTO #HolderTable EXEC dbo.uspNewSequentialUUIDCreateRange
@NewUUIDCount

select * from #HolderTable

DROP Table #HolderTable

--END TEST CODE

*/


这篇关于DotNet Framework中连续生成GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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