Merge Split Files

  • I am trying to move a database to a new server. The previous DBa for some reason split the database into 2 files on different drives. As the database is so small, when I move it I also want to combine these 2 files back into 1.

    What would be the recommended method for doing this? if I detach the database will it detach both files or combine them?

    Any suggestions welcomed! 😀

  • OK, I managed to merge the 2 database files by doing the following:

    1) Setting the database to single user mode

    2) Detach the database file

    3) Move files to the same folder as the other database files

    4) Attach the database file

    5) DBCC Shrinkfile(databasename,EMPTYFILE)

    However task 5) doesn't work for the transaction log. Does anyone know how I can safely merge the 2 transaction logs please?

    Regards Paul.

  • If the database is in simple recovery mode you can use something like:

    USE <dbname>

    GO

    CHECKPOINT

    GO

    ALTER DATABASE <dbname> REMOVE FILE dbname_log2

    GO

    Or if it's in full recovery mode you will need to run the alter database statement right after a tran log backup.

    You cannot remove the primary log file, only any additional log files.

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

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