Renaming SQL Server objects like table/Index/functions:Renaming the object is a very challenging and interesting part in SQL Server.
Scenario: I have created a table and my boss is asking me to change the name of the table.
How can I achieve it? This can achieved using sp_rename
Let's see, how we are achieving it
Creating the table named Venkat with two column id and nam
create table Venkat(id int,nam varchar(10))Am trying to create an index on the column id on the table venkat
create clustered index Venkat_Index on venkat(id )--------------------------------------------------------------------
Renaming the index name on the table venkatThe syntax is,
exec sp_rename 'tablename.OldIndexID','new index name','index'Example,
exec sp_rename 'venkat.venkat_index','Venkat_modified_index','index'--------------------------------------------------------------------
Renaming the column name on the table venkatThe syntax is,
exec sp_rename 'tablename.OldColumnID','new Column name','column'
Example,
exec sp_rename 'venkat.id','id1','column'--------------------------------------------------------------------
Renaming the name of the table
The syntax is,
exec sp_rename 'OldTableName','new Table Name'Example,
exec sp_rename 'venkat','New_Venkat'--------------------------------------------------------------------
While using this option, we used to get the below message from SQL Server
Caution: Changing any part of an object name could break scripts and stored procedures.
It indicates that the relative objects will get affected due to this change.
---------------------------------------------------------------------
Thanks and Regards,
Venkatesan Prabu .J