164502/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 previous_name to new_name;
This statement doesn't work.
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.
For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE
Windows mode and Mixed Mode – SQL ...READ MORE
Hey @Rajni, Verify if the server is running ...READ MORE
Follow these steps if you wish to ...READ MORE
I think this solution requires a CROSS JOIN implementation. ...READ MORE
INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE
A stored procedure is a set of ...READ MORE
I think these could be helpful for ...READ MORE
MERGE INTO YourTable T USING ...READ MORE
You can use the PIVOT function to ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.