Rename Column and rename sql server objects such as Tables, SP's

Here is syntax of the script for renaming any column
SP_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'

Here is syntax of the script for renaming any sql server objects such as Tables, SPs, Functions etc.
SP_RENAME '[OldTableName]' , '[NewTableName]'

Once any of the above scripts are executed the below caution statement will come.
Caution: Changing any part of an object name could break scripts and stored procedures.

It indicates, the rename of the object or object column has to be done in associated objects like Stored Procedures, Functions etc

Note:
If you have any constraints in the column like Primary Key constraint, Not Null constraint or indexing, rename will be performed forcefully. The constraints will remain as it is.
-------------------------------------------------------------------------------------------------------------
Other properties of SP_RENAME
-------------------------------------------------------------------------------------------------------------
Scenario 1: When I tried renaming a column in a table by name Table1 as below, the column Emp Nm got renamed to [EmployeeName] i.e. with square braces.
SP_RENAME 'Table1.[Emp Nm]' , Table1.[EmployeeName]', 'COLUMN';

So I wanted to eliminate those braces then I have to write below script to do so.
SP_RENAME 'Table1.[[EmployeeName]]]' , 'EmployeeName', 'COLUMN'

1 comment: