如何在 SQLServer 中生成指南?

我需要在 SQL 中创建一个 Id 作为 Guid (没有标识)如何做到这一点?我将 Id 定义为 unique 标识符,但在 Db 中保存的是000000-0000-0000-0000-000000000

157940 次浏览

This will generate a Guid in SQL Server:

SELECT NEWID()

A aspnet role created manually

DECLARE @ID UNIQUEIDENTIFIER
SET @ID = NEWID()


DECLARE @STAMP UNIQUEIDENTIFIER
SET @STAMP = NEWID()


INSERT INTO [dbo].[AspNetRoles]
([Id]
,[Name]
,[NormalizedName]
,[ConcurrencyStamp])
VALUES
(@ID
,'Admin'
,'ADMIN'
,@STAMP)

Create a variable of uniqueidentifier data type. Type the below code in SSMS and execute.

 DECLARE @guid uniqueidentifier = NEWID();
SELECT @guid as 'GUID';

Here we created a variable named guid of data type uniqueidentifier.