detach and reattach

  • when should we do detach and reattach ?

  • what are the advantages ?

  • It's one of the ways of moving a database's data and log files to different locations, maybe different drives. Can also be used to move a database from one server to another. Detach it from one server, copy the files to another, reattach there.

    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
  • In general, you will detach a db when you want to disable, or otherwise curtail use of it.

    This has the effect of "deleting" it from the server, without actually deleting the assoc'd files from disk. In order to re-attach a detached db, you must go through a couple steps to tell the server where to find the files.

    The other means of 'disabling' a db is to Take Offline, which has the effect of disabling access to it, but the server still manages it (maintains it in Object Explorer). This method is quicker and simpler, in that it requires only a few clicks to Take Offline or Bring Online.

    The usage for either of these will be dependant on the situation, and the desired results.

    -MarkO

    "You do not really understand something until you can explain it to your grandmother" - Albert Einstein

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

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