Click here to Skip to main content
13,597,610 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 1 Dec 2012
Licenced CPOL

SQL Server Function - SP_RENAME and NEWID

, 1 Dec 2012
Rate this:
Please Sign up or sign in to vote.
Getting overview of new SQL Server functions

Today, we will have an overview of two SQL Server functions


SP_RENAME is used to rename table name or rename any column of the table.
NEWID is used to extract random records from table.

Renaming of Column in Table  

sp_RENAME 'Tablename.ColumnName','NewColumnName','Column' 

I had a table named as Employee_Salary in my SQL Server 2012 under Northwind database. It has four columns ID (Primary Key), Employee_Name,Salary and Sal_Month. 

I want to rename column named as 'Employee_Name' to 'Employees_Name' 

So, below is the command that needs to be executed

sp_RENAME 'Employee_Salary.Employee_Name','Employees_Name','Column'

Once done, you will see that column name would be updated.

Renaming of Table  

We can rename the table with sp_RENAME function provided in SQL Server.


sp_RENAME 'TableName' , 'TableNewName'
Below is the command executed
sp_RENAME 'Employee_Salary','Employees_Salary'

NEWID() Function     

As told, NEWID() is used to extract random records from the table.

We had table named as Employees_Salary containing employees salary for all the months. Below are the records present in the table 


Below is the query to extract random records

select top 2 * from Employees_Salary order by NEWID() 
Below is the data extracted when executed the query


If we execute the above query again below is the data returned


So, you have seen every time we execute the same query we are getting different records from table.
Hope with this article of mine, you have become familiar with very little but important functions of SQL Server. 


Keep a running update of any changes or improvements you've
made here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
Please visit my blog to read more articles

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
Rob Eckert2-Dec-12 3:42
memberRob Eckert2-Dec-12 3:42 
GeneralMy vote of 1 Pin
Violet Tape1-Dec-12 22:57
memberViolet Tape1-Dec-12 22:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.180621.3 | Last Updated 2 Dec 2012
Article Copyright 2012 by Khanna_Varun
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid