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
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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 23rd, 2004, 08: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:

ALTER TABLE Tab TO TABLE
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.

Thanks,

Pankaj


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

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, 08:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use sp_rename to do that.

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #4 (permalink)  
Old September 28th, 2004, 05: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
Default

Hi,

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,

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

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, 03:31 AM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply


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 5 September 16th, 2013 10:11 AM
Rename Field using SQL spazband Access 5 May 20th, 2011 06:20 AM
SQL Rename a Field? seananderson BOOK: Beginning SQL 2 May 20th, 2011 06:19 AM
create SQL Server table from Access PorcupineRabbit SQL Server DTS 2 December 30th, 2005 05:11 AM
How to rename a table in SQL Server leo_vinay Classic ASP Databases 1 January 4th, 2005 11:48 PM



All times are GMT -4. The time now is 07:18 PM.


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