繁体   English   中英

SQL Server:使用特殊字符更新列

[英]SQL Server: update column with special characters

我是SQL Server的新手,请原谅我一个愚蠢的问题。

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

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

但是问题是team_code id必须放在大括号中,我不知道该怎么做。

你有什么建议吗?

谢谢^

尝试这种方式,因为newid()直接未设置大括号

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

而且你也尝试

insert into Teams (team_code, team_name, team_short) values ('{'+Convert( VARCHAR(max),NEWID())+'}',test,test)

您可以进行内联转换:

INSERT INTO Teams (team_code, team_name, team_short) 
VALUES ('{' + CAST(NEWID() AS VARCHAR(255)) + '}',test,test)

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

insert into Teams (team_code, team_name, team_short) 
values ('{' + newid() + '}', test, test);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM