• Very nice script, thanks for it. I have a suggestion for it so it will work also in a mirroring environment if not all databases are principle or if a database is offline...

    Just replace line 52 with this statement:

    DECLARE cur_Databases CURSOR FAST_FORWARD FOR

    SELECT DatabaseName = [name] FROM dbo.sysdatabases

    where status not in (32, 36, 48, 512, 528, 536, 1024, 2048, 3104,

    4096, 65568, 65664, 66048, 66056, 66560, 66568, 67072, 70664,

    4194336, 4194340, 4194352, 4194824, 4260360, 4194352, 4259872, 1073807392)

    ORDER BY DatabaseName

    That's all. Have a nice day!