Solved

EXECUTE MULTIPLE SP_RENAME STATEMENTS WITHIN QUERY ANALYZER

Posted on 2004-04-23
3
1,443 Views
Last Modified: 2008-03-03
Howdy,

Can anyone tell me how to execute multiple sp_rename statements from within query analyzer. I have quite a few tables that need to be renamed from tableone to tableone_old  and a corresponding number that need to be renamed from tableone_new to tableone as in the following example:

sp_rename ZIPS,ZIPS_OLD                        
sp_rename ZIPS1,ZIPS1_OLD      
sp_rename ZIPS_NEW,ZIPS                  
sp_rename ZIPS1_NEW,ZIPS1      

executing this generates a result of:

Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near 'sp_rename'.

Thanks,

Del
0
Comment
Question by:delclifton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
arbert earned 500 total points
ID: 10905888
put GO in between each statement to start the next batch....
0
 
LVL 34

Expert Comment

by:arbert
ID: 10905894
If you want to rename every table in a database, you can also do this:

sp_msforeachtable 'sp_rename ''?'',''?_old'''


Notice the above are NOT double quotes--they are double single quotes.

Brett
0
 

Author Comment

by:delclifton
ID: 10905941
Dang! Do I feel stupid. I had tried the GO but it was on each line i.e.

go sp_rename ZIPS,ZIPS_OLD                    
go sp_rename ZIPS1,ZIPS1_OLD

but got other errors. Putting go between each line did the trick. Thanks!

Del
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question