?
Solved

EXECUTE MULTIPLE SP_RENAME STATEMENTS WITHIN QUERY ANALYZER

Posted on 2004-04-23
3
Medium Priority
?
1,560 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

650 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