簡體   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