SQL Rename Column - How to Rename a Column in SQL - How to Change Column Name in SQL



Demo wikitechydatabase

  • Below is a selection from the wikitechytable table used in the examples:
sql-modify-column-1
  • In Microsoft SQL Server (MSSQL), you can rename a column using the sp_rename system stored procedure.

Syntax

  EXEC sp_rename 'table_name.old_column_name', 'new_column_name', 'COLUMN';
  • table_name: The name of the table that contains the column you want to rename.
  • old_column_nameThe current name of the column you want to rename.
  • new_column_name: The new name you want to assign to the column.
  • [new_data_type]: This is optional. If you want to change the data type of the column, specify the new data type here.
  • 'COLUMN': This is a keyword that specifies that you are renaming a column.
  • Here's an example of how to rename a column named "fees" to "fee" in a table named "wikitechytable":
EXEC sp_rename 'wikitechytable.fees', 'fee', 'COLUMN';
  • After running this SQL statement, the column will be renamed from "fees" to "fee." Please note that renaming a column can affect any SQL queries, stored procedures, or application code that reference the old column name, so make sure to update those accordingly after renaming the column.
sql-modify-column-1

Related Searches to SQL Rename Column - How to Rename a Column in SQL - How to Change Column Name in SQL