Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

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.

1 Answer

0 votes
by (40.7k points)

You can use sp_rename like this

EXEC sp_RENAME 'TableName.OldColumn_Name’, 'NewColumn_Name', 'COLUMN'

For more information you can refer to sp_rename (Transact-SQL)

Refer to this to get more details related to rename   SQL SERVER – How to Rename a Column Name or Table Name

Specifically, for your case you can use  this way:

EXEC sp_RENAME 'table_name.oldname', 'newname', 'COLUMN'

To enclose your values, always use single quotes.

Related questions

Browse Categories

...