如何在存储过程中生成新的 Guid? [英] How to generate a new Guid in stored procedure?
问题描述
我目前有一个存储过程,我想在其中向表中插入新行.
I currently have a stored procedure in which I want to insert new rows into a table.
insert into cars
(id, Make, Model)
values('A new Guid', "Ford", "Mustang")
所以主键 'id' 是一个 Guid.我知道如何在 C# 代码中创建新的 Guid,但在存储过程中我不确定如何为主键值生成新的 Guid.
So the primary key 'id' is a Guid. I know how to create a new Guid in C# code but within the stored procedure I'm unsure how to generate the new Guids for the primary key values.
推荐答案
通过 SQL Server,您可以使用功能 新的.您使用的是 C#,所以我假设您使用的是 SQL Server.我相信其他数据库系统也有类似的功能.
With SQL Server you can use the function NEWID. You're using C# so I assume that you're using SQL Server. I'm sure other database system have similar functions.
select NEWID()
如果您使用的是 Oracle,那么您可以使用 SYS_GUID()
函数.查看此问题的答案:在 Oracle 中生成 GUID
If you're using Oracle then you can use the SYS_GUID()
function. Check out the answer to this question: Generate a GUID in Oracle
这篇关于如何在存储过程中生成新的 Guid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!