for a hundred good reasons …. and I promise that at least a few are good … I find myself with almost 200 SQL server databases (mdf,ldf files) generated by different versions of sql server, most 2005.
I need to verify the integrity of each and follow up on the ones that fail.
after all that …. My question is:
Is it possible to attach – verify – detach each database using a batch file or a simple script?
I've used sqlcmd for similar jobs, but with this volume I thought I'd see if there was a simpler way.
Best Answer
This one was quite tricky. I didn't figure out how to access DBCC messages, but am working on it. Anyway, this Powershell script attaches databases, executes DBCC CHECKDB and detaches dbs.