Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 using a dos for look to run a checkdb

Author  Topic 

wardsan
Starting Member

48 Posts

Posted - 2010-09-07 : 04:56:54
Folks,
I am trying to run a checkdb on all databases on a sql server. I have the databases listed in a file database.txt e.g.
master
model
msdb
TestCorruption

My for loop:
for /f "eol=; delims=," %%i in (d:\SQLScripts\database.txt) do (
sqlcmd -Svirttst140s -E -q"dbcc checkdb(%%1)" -od:\SQLScripts\dbcc.out')

Am getting a syntax error near %1
It was a bit of a long shot but is there anyway I can make this work?

TIA
Sandra


webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-07 : 05:00:31
Try %%i instead of %%1


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

wardsan
Starting Member

48 Posts

Posted - 2010-09-07 : 05:15:31
I am an idiot!
thanks a mill
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-07 : 05:18:02
We all are this kind of idiots sometimes.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

wardsan
Starting Member

48 Posts

Posted - 2010-09-07 : 05:54:12
Stuck again.

for /f "eol=; delims=," %%i in (d:\SQLScripts\database.txt) do (
sqlcmd -Svirttst140s -E -q"dbcc checkdb(%%i)" -od:\SQLScripts\dbcc_%%i.lst -W -h-1 )

It is working but only running for the first entry in database.txt i.e. master. I have to an exit to get it to move on. I'm not sure why it doesn't happen automatically or how to get it to do it automatically.

D:\SQLScripts>(sqlcmd -Svirttst140s -E -q"dbcc checkdb(master)" -od:\SQLScriptsdbcc_master.lst -W -h-1 )
1> exit

D:\SQLScripts>(sqlcmd -Svirttst140s -E -q"dbcc checkdb(tempdb)" -od:\SQLScriptsdbcc_tempdb.lst -W -h-1 )
1>
Go to Top of Page
   

- Advertisement -