0

我是 SQL Server 的新手,所以请原谅我可能会提出愚蠢的问题。

我有一个数据库,我需要生成我通过使用实现的随机 idnewid()

insert into Teams (team_code, team_name, team_short) 
values (newid(),test,test)

但问题是team_codeid 需要放在大括号中,我不知道该怎么做。

你有什么建议吗?

谢谢^

4

3 回答 3

0

Try this way because newid() direct not set curly brackets

DECLARE @ID varchar(max);
    SET @ID = newid();
select @ID
insert into Teams (team_code,team_name,team_short) values ('{'+@ID+'}',test,test)

AND also you try as

insert into Teams (team_code, team_name, team_short) values ('{'+Convert( VARCHAR(max),NEWID())+'}',test,test)
于 2014-08-22T11:14:00.237 回答
0

您可以进行内联投射:

INSERT INTO Teams (team_code, team_name, team_short) 
VALUES ('{' + CAST(NEWID() AS VARCHAR(255)) + '}',test,test)
于 2014-08-22T12:15:34.470 回答
-1

所以你想在创建的唯一标识符字符串中添加一个前导 { 和一个尾随 }?这是 SQL Server,对吧?然后用 + 连接字符串,如下所示:

insert into Teams (team_code, team_name, team_short) 
values ('{' + newid() + '}', test, test);
于 2014-08-22T11:01:40.403 回答