--HOW TO MOVE THE LOCATION OF THE DATABASE USING ALTER DATABASE (similar to attach and detach work)
SELECT * FROM SYS.DATABASE_FILES
--read the physical_name of the current location of the database before moving the database files
ALTER DATABASE DATABASENAME
MODIFY FILE (NAME = 'NAME' , FILENAME = 'NEW_LOCATION.mdb');
ALTER DATABASE DATABASENAME
MODIFY FILE (NAME = 'NAME' , FILENAME = 'NEW_LOCATION.ldb');
--the above command have moved the database file locially now need to move it physically
--before moving the file physically to new location put the database in OFFLINE mode
--run the below statement to make database in OFFLINE mode
ALTER DATABASE DATABASENAME SET OFFLINE
--now move the database file physically to its new location after moving run the below statement
ALTER DATABASE DATABASENAME SET ONLINE
--run the below commant to see the new changes
SELECT * FROM SYS.DATABASE_FILES
--Note its more convient then Attach and Detach
No comments:
Post a Comment