开发者

Rename column in SQL Server

开发者 https://www.devze.com 2022-12-22 19:40 出处:网络
I tried the following code. Although I don\'t get any errors, it did not do it. SELECT * FROM Categories EXEC sp_renam开发者_如何学运维e \'Active\', CategoriesActive

I tried the following code. Although I don't get any errors, it did not do it.

SELECT * FROM Categories EXEC sp_renam开发者_如何学运维e 'Active', CategoriesActive


EXEC sp_rename 'Categories.Active', 'CategoriesActive', 'COLUMN'


FOR MSSQL :

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

FOR MYSQL : Use ALTER TABLE to do this

ALTER TABLE tbl_name CHANGE [COLUMN] old_col_name new_col_name

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

ALTER TABLE t1 CHANGE a b INTEGER;


You don't need to use that select in front, and the syntax should be like:

EXEC sp_rename 
    @objname = 'Categories.Active', 
    @newname = 'CategoriesActive', 
    @objtype = 'Type_of_your_column'
0

精彩评论

暂无评论...
验证码 换一张
取 消