ATTACH Rebuild Log

  • Hi All

    If a database has been cleanly shutdown, detached and the transaction log deleted.

    Is there a difference between:

    ......

    FOR ATTACH

    And.....

    ......

    FOR ATTACH_REBUILD_LOG

    I am under the impression that FOR ATTACH is all you need because SQL Server will create a new transaction log.

    If my understanding is correct, what's the purpose of FOR ATTACH_REBUILD_LOG then?

    Thanks

  • https://msdn.microsoft.com/en-us/library/ms176061.aspx

    FOR ATTACH [ WITH < attach_database_option > ]

    Specifies that the database is created by attaching an existing set of operating system files. There must be a <filespec> entry that specifies the primary file. The only other <filespec> entries required are those for any files that have a different path from when the database was first created or last attached. A <filespec> entry must be specified for these files.

    FOR ATTACH requires the following:

    All data files (MDF and NDF) must be available.

    If multiple log files exist, they must all be available.

    If a read/write database has a single log file that is currently unavailable, and if the database was shut down with no users or open transactions before the attach operation, FOR ATTACH automatically rebuilds the log file and updates the primary file.

    FOR ATTACH_REBUILD_LOG

    Specifies that the database is created by attaching an existing set of operating system files. This option is limited to read/write databases. There must be a <filespec> entry specifying the primary file. If one or more transaction log files are missing, the log file is rebuilt. The ATTACH_REBUILD_LOG automatically creates a new, 1 MB log file.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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