Why detach?

  • If I am able to attach a database that was not officially detached, then why detach? BOL says to only attach databases that have been detached - anyone know why?

  • Can you explain in a bit more detail the part 'If I am able to attach a database that was not officially detached,'?

  • If I stop the mssqlserver service and copy the .mdf and .ldf files to a new location, and bring up the service, I can then attach the copied files as a new database. However, BOL says that I should attach files that were previously detached - but I don't see that this is necessary. Any ideas?

  • House keeping, updating of system tables in master! Hopefully someone else can shed a bit more light on details what MS SQL Server does internally / behind the scene when detaching a database.

  • Detaching just cleans up sysdatabases and sysfiles. Nothing at all wrong with stopping the server, copying the files to a different server and attaching. Doesn't affect anything. You'd use detach to avoid stopping the service on the original server. If you need a copy without stopping the server OR losing access, then you have to do a full backup and restore on the other server.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • "You'd use detach to avoid stopping the service on the original server"

    So does that mean that the database files can be detached while the database is operational???

  • The database can be detached while the server is operational, but not the database. All users must be out of the database before the database can be detached. The server will still hold locks on the files while that database is attached. Stopping the server OR detaching will ensure the files are unlocked and in a consistant state.

    -Dan


    -Dan

Viewing 7 posts - 1 through 6 (of 6 total)

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