Rename a column in SQL Server

I tried the following code. Although I am not getting any errors, he did not.

SELECT * FROM Categories EXEC sp_rename 'Active', CategoriesActive 
+41
sql-server
Mar 15 '10 at 15:10
source share
3 answers
 EXEC sp_rename 'Categories.Active', 'CategoriesActive', 'COLUMN' 
+75
Mar 15 '10 at 15:15
source share

FOR MSSQL:

 EXEC sp_rename 'TABLENAME.OLD_COLUMNNAME', 'NEW_COLUMNAME', 'COLUMN'; 

FOR MYSQL: use ALTER TABLE for this

 ALTER TABLE tbl_name CHANGE [COLUMN] old_col_name new_col_name 

You can rename a column using the CHANGE clause old_col_name new_col_name column_definition. To do this, specify the old and new column names and the definition that the current column has. For example, to rename an INTEGER column from a to b, you can do this:

 ALTER TABLE t1 CHANGE ab INTEGER; 
+37
Mar 15 '10 at 15:16
source share

You do not need to use this flag in front, and the syntax should look like this:

 EXEC sp_rename @objname = 'Categories.Active', @newname = 'CategoriesActive', @objtype = 'Type_of_your_column' 
+6
Mar 15 '10 at 15:15
source share



All Articles