• Again... the reason I did what I did was I couldn't come up with a way to run

    DBCC CHECKPRIMARYFILE (N''' + @filename + ''',2)

    Which gets the actual name of the database from the database itself.

    I had found in my testing that 90% of the databases followed our naming conventions, but the other 10% (400) did not. So I needed to probe the mdf file to find out what the actual database name was. New databases all follow the naming convention. The older databases are used by our customers as well though and we had a very small time window to do this (approx 5 hours, including copying almost 2 TB of Databases to their new homes).

    Tracing how SSMS 2K5 does it showed me DBCC CHECKPRIMARYFILE, which only appears to work on an mdf that isn't attached to a SQL server, it's also not documented in BOL (yet it's what MS uses).

    Since the DBCC command returns a small result set for a single file at a time, I couldn't come up with a good way to do it other than to run DBCC CHECKPRIMARYFILE for each database mdf file, one at a time.

    All told, the attach routine took less than 10 minutes to attach 1000 databases per instance to each instance. The rest of the time was spent copying mdf files to their new homes.



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]