• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1598
  • Last Modified:

EXECUTE MULTIPLE SP_RENAME STATEMENTS WITHIN QUERY ANALYZER

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
delclifton
Asked:
delclifton
  • 2
1 Solution
 
arbertCommented:
put GO in between each statement to start the next batch....
0
 
arbertCommented:
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
 
delcliftonAuthor Commented:
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now