Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2004, 08:51 AM
Authorized User
 
Join Date: Sep 2003
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


 
Old June 23rd, 2004, 08:55 AM
Registered User
 
Join Date: Apr 2004
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'

 
Old June 23rd, 2004, 08:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can use sp_rename to do that.

_________________________
-Vijay G
Strive for Perfection
 
Old September 28th, 2004, 05:29 AM
Authorized User
 
Join Date: Sep 2004
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...;)
 
Old May 28th, 2008, 08:42 PM
Registered User
 
Join Date: May 2008
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'


 
Old June 27th, 2008, 03:31 AM
Registered User
 
Join Date: Jun 2008
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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename a Column using SQL pipelineconsulting Classic ASP Databases 7 September 21st, 2017 04:16 PM
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 06:11 AM
How to rename a table in SQL Server leo_vinay Classic ASP Databases 1 January 5th, 2005 12:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.