Web Analytics Made Easy - Statcounter
 We often need to change the name of a column of a table to a new name. We  can do this with the help of the Exec Sp_rename command.

 The Syntax of the Sp_rename is given below:-

 Exec sp_rename ‘TableName.[OldColumnName]’, ‘[NewColumnName]’, ‘Column’

 For example, suppose we have a table called Employee who has the following structure:-

 CREATE TABLE Employee (Emplyeeid int identity(1,1),
                                      Empnumber nvarchar(10),
                                      Firstname nvarchar(150), 
                                      Lastname nvarchar(150),
                                      Age int, 
                                      Phoneno nvarchar(15), 
                                      Address nvarchar(200),
                                      Empdate datetime)

Now suppose we insert the following data into the table Employee

Insert into Employee values(‘VIV123’, ‘Vivek’, ‘Johari’, 27, ‘9211134’, ‘Delhi’, getdate())

If we execute the Select command into the table Employee, we get the following result:-

Suppose now  we want to change the column name Firstname to Fname the we use the given query:-

Exec Sp_rename ‘Employee.Firstname’, ‘Fname’, ‘column’

If we again execute the Select command into the table Employee, we get the following result:-

Here the column name “Firstname” changed to the column “Fnamn”.


Discover more from Technology with Vivek Johari

Subscribe to get the latest posts sent to your email.

By vivekjohari

I am currently working as a Senior Database Professional and have around 18 years of experience in database. Degree:- Master Degree in Computer(MCA) Certification course in Data Science & Machine Learning from Indian Institute of Technology (IIT), Delhi Work experience:- Designing of the database. Database Optimization. Writing Complex Stored Procedures,Functions,Triggers etc. Designing and developing SSIS & DTS packages. Designing SQL Reports using SSRS. Database Server Maintenance. Certification:- MCTS: DA-100: Analysing Data with Microsoft Power BI MCTS: DP-300: Administering Relational Databases on Microsoft Azure Microsoft certified Sql DBA in Sql server 2008 (MCTS). Microsoft certified BI professional in Sql server 2008 (MCTS). Oracle certified profession DBA in ORACLE 10g (OCP) certified profession DBA in ORACLE 9i (OCP) My other publication Technical Blog:- Technologies with Vivek Johari Guest Author and Blogger at sqlservercentral.com

13 thought on “Renaming a column in Sql Server”
  1. Nice article vivek, can you please put some more light on the relevance of the last parameter i.e. 'column'.

    Hope you got me, if we can use this statement to rename tables as well by changing the last parameter? Plz explain.

  2. HI Manish,
    Thanks for your comment. The last parameter 'column' is used since through the last parameter sql server identifies that we are going to rename the column of the table.

    For renaming the table, we don't need this parameter.The syntax for renaming the column is

    Exec sp_rename 'Oldtablename', 'Newtablename'

  3. hi vivek,

    thanks for the quick followup to this, but my doubt still remains there. If last parameter is only to get the input as column, then why not to leave it? and if, some other parameter can also be passed to have a different functionality, then what is it? Please clarify.

Leave a Reply

Discover more from Technology with Vivek Johari

Subscribe now to keep reading and get access to the full archive.

Continue reading