Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using SQL Server 2008 and Navicat.

(我正在使用SQL Server 2008和Navicat。)

I need to rename a column in a table using SQL.

(我需要使用SQL重命名表中的列。)

ALTER TABLE table_name RENAME COLUMN old_name to new_name;

This statement doesn't work.

(此声明不起作用。)

  ask by Serhio g. Lazin translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
335 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use sp_rename

(使用sp_rename)

EXEC sp_RENAME 'TableName.OldColumnName' , 'NewColumnName', 'COLUMN'

See: SQL SERVER – How to Rename a Column Name or Table Name

(请参阅: SQL SERVER - 如何重命名列名或表名)

Documentation: sp_rename (Transact-SQL)

(文档: sp_rename (Transact-SQL))

For your case it would be:

(对于你的情况,它将是:)

EXEC sp_RENAME 'table_name.old_name', 'new_name', 'COLUMN'

Remember to use single quotes to enclose your values.

(请记住使用单引号括起您的值。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...