Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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.4k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...