Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change column name in SQL Server 2008

How to change predefined column name to a new name.

eg: Column name is "Accounts"
I want to change it to "A/c"

alter table emp change Accounts....[What next]

like image 988
techie Avatar asked Jul 10 '12 20:07

techie


People also ask

When to change the column name in a SQL Server table?

SQL Server allows us to change the column whenever we need. We will rename the table columns when the column name is non-meaningful or does not fulfill the purpose of its creation.

How to rename a column in SQL Server management studio?

Using SQL Server Management Studio To rename a column using Object Explorer In Object Explorer, connect to an instance of Database Engine. In Object Explorer, right-click the table in which you want to rename columns and choose Rename.

How do I change the name of a column in Excel?

In Object Explorer, right-click the table in which you want to rename columns and choose Rename. Type a new column name. In Object Explorer, right-click the table to which you want to rename columns and choose Design. Under Column Name, select the name you want to change and type a new one.

How do I change a column in an existing MySQL table?

SQL Server allows you to perform the following changes to an existing column of a table: 1 Modify the data type 2 Change the size 3 Add a NOT NULL constraint


1 Answers

The script for renaming any column :

sp_RENAME 'TableName.[OldColumnName]' , 'NewColumnName', 'COLUMN'

(Note that you don't use escapes in the second argument, surprisingly.)

The script for renaming any object (table, sp etc) :

sp_RENAME '[OldTableName]' , 'NewTableName'

see here for further info

like image 74
03Usr Avatar answered Sep 20 '22 23:09

03Usr