How to rename table column in sql server

One day in office, we were working with team for application testing. Suddenly we asked to rename the table column using t-sql command. In sql server, we can use sp_rename command to rename table, sp and column in database.

Using below script you can change table name or column.

sp_rename ‘tablename.[old_column_name]’, ‘New_column_name’,’Column’

example : if we want to rename “st_name” column from st_details table with “StudentName” then script would be like this :

sp_rename ‘st_details.st_name’,’StudentName’,’COLUMN’

Now lets see how can we rename table using sp_rename command.

Syntax for renaming table : sp_rename ‘oldtablename’, ‘newtablename’

Consider we have to rename st_details table to studentdetails then script would be like this

sp_rename ‘stdetails’,’studentdetails’

To verify the change table name by selecting table.

Leave a Reply

  

  

  


5 + = 8