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]
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With