Please rate this item: 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

SQL: Detach, Move, and re-Attach database

The Transact-SQL Script below, is useful if you want to standardise the location of your databases. I have been managing a server whereby databases created by other people were created all over the place!! Therefore, this script was written to make life so much easier. 🙂

Be sure to read through the script before running it.

You may need to allow xp_cmdshell access. Use the Surface Area Configuration tool to do this.

If you get an error, please refresh your list of databases in Management Studio. If you database has disappeared, it will just need to be re-attached.

Please also note, that I haven’t tested it in SQL Server 2000 where a full text catalogue exists.

As always 1, please ensure you test any script taken from my website on a test/development machine, before running on a production server.

If you want to produce a list of database files (either before or after), please see My related post – List of database files

Please leave any comments that you have 🙂

  1. Please ensure you test any script taken from my website on a test/development machine, before running on a production server.

Leave a Reply

Your email address will not be published. Required fields are marked *

CJayMead's SQL Server, Endeca, MS Office Help © 2018