In this article we are going to show you,How to Rename Table Name and Column Name in SQL Server with example.
Rename Table Name and Column Name in SQL Server:-
To Rename Table Name and Column Name in SQL Server we are going to use the stored procedure SP_RENAME.
Syntax to rename Table Name and Column Name in SQL Server:-
-- The script for renaming any object in a database is sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN' -- The script for renaming any object in a database is :- sp_RENAME '[OldTableName]' , '[NewTableName]'
We are going to use the Employees Details table present in our AdventureWorks2012 Database for demo purpose
- SQL Server Rename Table Name
USE [AdventureWorks2012] GO SP_RENAME 'Employee', 'EmployeDetails'
Output:-
- Now select records from new table EmployeDetails
- Renaming table column to new name in SQL Server
USE [AdventureWorks2012] GO SP_RENAME 'EmployeDetails.Name', 'FullName', 'COLUMN'
Output:-
- Now select records from new table EmployeDetails and in the below screenshot you can see the changed column name from Name to FullName.
Output:-