Scripting around a DBCC Checkdb

  • Not being a DBA or DBA programmer, I apologize in advance is this is a little base, but I can't seem to find the answer from the SQL Knowledgebase.

    I have been asked to automate a database integrity check from VBScript (VBScript is used to automate our current Disaster Recovery data replication - this would just be an extension to that code).

    I need to basically do the following:

    Attach a list of databases

    Run a DBCC Checkdb against them and get an overall success/fail

    Detach the databases.

    I can handle the attach/detach through SQLDMO objects, but how do I run a DBCC and get a simple Success/Fail result? Someone has suggested running the DBCC check via the SQLMAINT.EXE util - would this be a viable option?

    Thanks for any advice.

  • Hi mpeters,

    quote:


    I can handle the attach/detach through SQLDMO objects, but how do I run a DBCC and get a simple Success/Fail result? Someone has suggested running the DBCC check via the SQLMAINT.EXE util - would this be a viable option?


    yes, it is a viable option.

    If you don't want to deal with the command line, you can use xp_sqlmaint as explained in BOL.

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • "C:\Program Files\Microsoft SQL Server\MSSQL\Binn\sqlmaint" -S lene -D Northwind -CkDB -CkCat -Rpt C:\Northwind.rpt

    if errorlevel 1 echo ERROR

    if errorlevel 0 echo OK

    "C:\Program Files\Microsoft SQL Server\MSSQL\Binn\sqlmaint" -S lene -D MSDB -CkDB -CkCat -Rpt C:\MSDB.rpt

    if errorlevel 1 echo ERROR

    if errorlevel 0 echo OK

    It worked!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply