Thursday, September 10, 2015

How to rename column name in a table

Column name can be changed in two ways 

A) SQL server management studio-->right click on the database-->select table and expand-->select column name which you want to rename--> change the name

B)By Using Query:-

SQL server allows you to rename column name by using sp_rename procedure which is already written in the procedure library.
Syntax:- sp_rename 'tablename.old column name','new column name','column'
         Ex:-sp_rename '','Fullname','column'

name column changed to Full name

Renaming Table name 

In same way we can re-name our table also  and below query used to rename table name

Here department is my old table 

Syntax:- sp_RENAME 'OldTableName' , 'Newtablename' 
       Ex:-sp_rename 'department','mydepartment'

Now table name is changed

Renaming Database:-
 for explanation purpose a test database has been created here

create database testdata

Syntax:- sp_renamedb 'old database name','new database name'
           Ex:-sp_renamedb 'testdata','nedb'