如何从 C# 或 T-Sql 中给定的 GUID 生成新的 GUID?
我想复制 sqlserver 表行并插入到该表 self 中,该表具有以下字段:
Id :uniqueidentifier
ParentId: uniqueidentifier
Name: varchar(50)
Sort: float
UserId: uniqueidentifier
Id 和 ParentId 现有关系。
我想出了一个解决方案:
Insert into table1 (Id, ParentId,Name,Sort)
Select dbo.gen(id,1) as id, dbo.gen(ParentId,1) as ParentId ,Name,Sort from table1
where UserId='XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
gen 函数是从给定 GUID 生成新 GUID 的方法,
后面是 C# 描述,我们可以在 CLR SQL Server 用户定义函数中使用:
public Guid GenerateNewGuid(Guid from,int seed)
{
return .....
}
请帮助我如何实现此函数?
如果您对我的情况有其他解决方案,请告诉我
问候。
吉姆
I want to copy a sqlserver table rows and insert into this table self ,this table have this fields:
Id :uniqueidentifier
ParentId: uniqueidentifier
Name: varchar(50)
Sort: float
UserId: uniqueidentifier
Id and ParentId Existing relationships.
I came up with a solution:
Insert into table1 (Id, ParentId,Name,Sort)
Select dbo.gen(id,1) as id, dbo.gen(ParentId,1) as ParentId ,Name,Sort from table1
where UserId='XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
the gen function is method that Generate a new GUID from a given GUID
follow is a C# description and we can using in CLR SQL Server User-Defined Function:
public Guid GenerateNewGuid(Guid from,int seed)
{
return .....
}
please help me how can i implement this function?
if you have other solution about my situation ,please let me know
Regards.
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GUID 是一个(全局唯一标识符),它不像 AutoId 那样只能加 1。GUID
意味着唯一的句点。 wiki
A GUID is a (Globally unique identifier), it's not like a AutoId were you can just increment by 1.
A GUID is meant to be Unique period. wiki
您可以使用 NEWID() 在 SQL 中生成新的 GUID
如果需要, “序列”的一些概念使用NEWSEQUENTIALID()
然而,没有像兰德这样的“种子”盛宴。
所以你的 SQL 就变成了……
You can generate a new GUID in SQL with NEWID()
If you want some concept of "sequence" use NEWSEQUENTIALID()
However, there is no "seed" feasture like RAND.
So your SQL becomes...
只需创建一个新的:
指南没有排序或类似的东西。没有像
newGuid = oldGuid + 1
这样的算法。Just create a new one:
Guids are not ordered or something like that. There is no algorithm like
newGuid = oldGuid + 1
.