What is the best practice when it comes to renaming a table column using SQL (MS SQL Server 2005 variant)? This assumes that there is data in the column that must be preserved.
It is not possible to rename a column using the ALTER TABLE statement in SQL Server. Use sp_rename instead. To rename a column in SparkSQL or Hive SQL, we would use the ALTER TABLE Change Column command.
Here are the steps explaining how to change column name in SQL by Double click on the column name: Step-1: Follow this path: Databases > Tables > Columns. Step-2: Choose the column name you want to change and then double-click. Step-3: Give a name to your selected column.
You have to use a stored proc to rename a column. The following will rename your column from 'oldColumnName' to 'newColumnName' without affecting any data.
EXEC sp_rename 'tableName.[oldColumnName]', 'newColumnName', 'COLUMN'
Obviously you'll have to update any code / stored procs / SQL that uses the old name manually.
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