我正在尝试重命名列(如果存在)
GO
IF EXISTS(SELECT 1 FROM sys.columns WHERE [name] = N'MinDuration'
AND [object_id] = OBJECT_ID(N'Category'))
BEGIN
sp_RENAME 'Category.MinDuration', 'SingleDuration' , 'COLUMN'
END
GO
但是收到错误Incorrect syntax near sp_RENAME. Expecting CONVERSATION, DIALOG, DISTRIBUTED or TRANSACTION
如果我的列存在于表中,如何重命名列?
答案 0 :(得分:11)
首先尝试exec
:
IF EXISTS(SELECT 1 FROM sys.columns WHERE [name] = N'MinDuration'
AND [object_id] = OBJECT_ID(N'Category'))
BEGIN
EXEC sp_RENAME 'Category.MinDuration', 'SingleDuration' , 'COLUMN'
END;