Rename column SQL Server 2008

0 votes

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 previous_name to new_name;

This statement doesn't work.

If you need to know more about SQL, it is recommended to go for the SQL Online Course today.

Feb 23, 2022 in Database by Neha
• 9,020 points

edited Feb 23, 2022 by Neha 673 views

1 answer to this question.

0 votes

Use sp_rename

EXEC sp_RENAME 'TableName.PreviousColumnName' , '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.previous_name', 'new_name', 'COLUMN'

Don't forget to use single quotes to enclose your values.

answered Feb 23, 2022 by Vaani
• 7,070 points

Related Questions In Database

0 votes
1 answer

How can I create a unique constraint on my column (SQL Server 2008 R2)?

The "indexes and keys" dialogue, not the ...READ MORE

answered Sep 20, 2022 in Database by narikkadan
• 63,600 points
900 views
0 votes
1 answer

How to rename a column in a database table using SQL?

For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,020 points
759 views
0 votes
0 answers

Where can I find the Northwind database for Microsoft SQL Server 2008

To hone my Linq-fu , I'm looking ...READ MORE

Aug 15, 2022 in Database by Kithuzzz
• 38,000 points
555 views
0 votes
0 answers

SQL Server: Invalid Column Name

I am in the process of changing ...READ MORE

Aug 19, 2022 in Database by Kithuzzz
• 38,000 points
1,356 views
0 votes
0 answers

How to update Identity Column in SQL Server?

With 200 records currently, I want to ...READ MORE

Aug 9, 2022 in Database by Kithuzzz
• 38,000 points
1,360 views
0 votes
0 answers

Simple DateTime sql query

How do I query the DateTime database ...READ MORE

Aug 12, 2022 in Database by Kithuzzz
• 38,000 points
609 views
0 votes
0 answers

Calculate time difference in minutes in SQL Server

I require the minutes-based time difference between ...READ MORE

Aug 13, 2022 in Database by Kithuzzz
• 38,000 points
1,219 views
0 votes
0 answers

How can I select the first day of a month in SQL?

I only need to choose the given ...READ MORE

Aug 14, 2022 in Database by Kithuzzz
• 38,000 points
624 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
819 views
0 votes
1 answer

Convert Rows to columns using 'Pivot' in SQL Server

You can use the PIVOT function to ...READ MORE

answered Feb 8, 2022 in Database by Vaani
• 7,070 points
1,605 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP