Rename column SQL Server 2008

I am using SQL Server 2008 and Navicat. I need to rename a column in a table using SQL.

ALTER TABLE table_name RENAME COLUMN old_name to new_name;

This statement doesn't work.


Use sp_rename

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

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

Documentation: 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.


Alternatively to SQL , you can do this in Microsoft SQL Server Management Studio. Here are a few quick ways using the GUI:

First Way

Slow double-click on the column. The column name will become an editable text box.


Second Way

Right click on column and choose Rename from the context menu.

For example:

重命名列名称


Third Way

This way is preferable for when you need to rename multiple columns in one go.

  • Right-click on the table that contains the column that needs renaming.
  • Click Design.
  • In the table design panel, click and edit the textbox of the column name you want to alter.
  • For example: MSSMS表设计实例

    NOTE: I know OP specifically asked for SQL solution, thought this might help others :)


    尝试:

    EXEC sp_rename 'TableName.OldName', 'NewName', 'COLUMN'
    
    链接地址: http://www.djcxy.com/p/4220.html

    上一篇: 如何从私人数据创建示例数据集(用无用的占位符替换变量名称和级别)?

    下一篇: 重命名SQL Server 2008列