SQL - Structured Query Language |
RENAME TABLEThe sp_rename system procedure is used to rename an existing user defined table, column, index, alias data type or user-defined type name for the current database. The sp_rename cannot be used to change system data types and system objects information. INDEX name is automatically renames when PRIMARY KEY or UNIQUE constraint is renamed. PRIMARY KEY constraint name is automatically renames when INDEX is renamed. SQL Server does not recommend to rename stored procedure, function, view and trigger object name, when update this name the related object name does not rename. Example 01 Rename Existing Table Name The following example is used to rename an existing Employee table name into EMP_TEST that stored in the default dbo schema of eBusiness database. -- Rename Existing Table Name --
USE eBusiness GO
sp_rename 'dbo.Employee','EMP_TEST' Example 02 Rename Existing Column Name The following example is used to rename an existing EMP_TEST table's Emp_Code column name into Emp_ID that stored in the default dbo schema of eBusiness database. -- Rename Existing Column Name --
USE eBusiness GO
sp_rename 'dbo.EMP_TEST.Emp_Code','Emp_ID','COLUMN' |
* * * * *