Monday, September 6, 2010

Renaming a column in Sql Server

 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".

Friday, September 3, 2010

Thanks for supporting this blog and make it successful

Hi friends
Thank you very much for supporting this blog. It really give me lots of encouragement to share my knowledge with my friends. Due to some other high priorities, I was not able to publish any articles on this blog from last few months. But now I am busy with writing many articles through which I can share my experience with you.
I am very soon going to publish many articles on this blog which includes

1) Sql concept (Triggers, Cursor, Merge, CTE, Derived tables, linked server etc.)

2) Sql Server Business Intelligence ( SSIS, SSAS, SSRS)

3) Oracle concepts

4) Many more interview questions on SQL Server and SSIS, SSAS, SSRS

5) Interview Questions on PL/SQL

6) Unix Concepts

So keep visiting my blog regularly. Also I am trying to modify my existing articles by adding more informations in them.

Also keep giving me your valuable feedback so that I can improve my articles.

Best Regards