scope-identity

SCOPE_IDENTITY() for GUIDs?

徘徊边缘 提交于 2019-11-26 18:40:00
Can anyone tell me if there is an equivalent of SCOPE_IDENTITY() when using GUIDs as a primary key in SQL Server? I don't want to create the GUID first and save as a variable as we're using sequential GUIDs as our primary keys. Any idea on what the best way to retrieve the last inserted GUID primary key? You can get the GUID back by using OUTPUT. This works when you're inserting multiple records also. CREATE TABLE dbo.GuidPk ( ColGuid uniqueidentifier NOT NULL DEFAULT NewSequentialID(), Col2 int NOT NULL ) GO DECLARE @op TABLE ( ColGuid uniqueidentifier ) INSERT INTO dbo.GuidPk ( Col2 ) OUTPUT

Why does select SCOPE_IDENTITY() return a decimal instead of an integer?

非 Y 不嫁゛ 提交于 2019-11-26 06:38:50
问题 So I have a table with an identity column as the primary key, so it is an integer. So, why does SCOPE_IDENTITY() always return a decimal value instead of an int to my C# application? This is really annoying since decimal values will not implicitly convert to integers in C#, which means I now have to rewrite a bunch of stuff and have a lot of helper methods because I use SQL Server and Postgres, which Postgres does return an integer for the equivalent function.. Why does SCOPE_IDENTITY() not