Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old June 23rd, 2004, 09:51 AM
Authorized User
Join Date: Sep 2003
Location: , , .
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rename a table through SQL in SQL Server

Hi everyone,

Does anyone know the SQL statement to rename a table in SQL Server. I want to write a stored procedure that will rename a bunch of tables.

I tried statements like:

RENAME TABLE Tab TO Table (This works on Oracle).

But I have had no luck so far. If someone can offer any help, I would be grateful.



Reply With Quote
  #2 (permalink)  
Old June 23rd, 2004, 09:55 AM
Registered User
Join Date: Apr 2004
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Just use the stored procedure that already exists. sp_rename 'old_table_name', 'new_table_name'

Reply With Quote
  #3 (permalink)  
Old June 23rd, 2004, 09:56 AM
Friend of Wrox
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post

You can use sp_rename to do that.

-Vijay G
Strive for Perfection
Reply With Quote
  #4 (permalink)  
Old September 28th, 2004, 06:29 AM
Authorized User
Join Date: Sep 2004
Location: Delhi, Delhi, India.
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Lalit_Pratihari


Yes, you can use sp_rename for renaming a table or column in SQL Server. The only difference is that if you want to rename a column witbin a table you need to provide proper namespace.

for e.g.

for renaming a table
EXEC sp_rename 'Old_TableName', 'New_TableName'

for renaming a column
EXEC sp_rename 'TableName.[Old_ColumnName]', 'TableName.[New_ColumnName]', 'COLUMN'

Hope this helps,

Life Means More...;)
Reply With Quote
  #5 (permalink)  
Old May 28th, 2008, 09:42 PM
Registered User
Join Date: May 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Hi everyone,

I am agree with Lalit that sp_rename is helpful in this regard. But for Column rename use the following format :

EXEC sp_rename 'TableName.[Old_ColumnName]', 'New_ColumnName', 'COLUMN'

Reply With Quote
  #6 (permalink)  
Old June 27th, 2008, 04:31 AM
Registered User
Join Date: Jun 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

It's my first time coming to this forum,
to begin with,I'd give a self-introduction and my wish
I come from China,a student on the major of e-commerce
I have been studying asp.net 2.0 and English altogether,
I am happy to communicate with all of you from different areas and
certainly willing to make friends with you.

learning asp.net 2.0 needs help and communications!
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename a Column using SQL pipelineconsulting Classic ASP Databases 7 September 21st, 2017 05:16 PM
Rename Field using SQL spazband Access 5 May 20th, 2011 07:20 AM
SQL Rename a Field? seananderson BOOK: Beginning SQL 2 May 20th, 2011 07:19 AM
create SQL Server table from Access PorcupineRabbit SQL Server DTS 2 December 30th, 2005 06:11 AM
How to rename a table in SQL Server leo_vinay Classic ASP Databases 1 January 5th, 2005 12:48 AM

All times are GMT -4. The time now is 03:21 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.