Today’s post is a quick one as I am a bit under the cosh.
There are many ways to move database files, detach and attach, backup and restore, alter database. But what can you do if the files you want to move belong to a database being used in replication? Here is one solution I used recently;
-- set database to restricted user mode ALTER DATABASE databasename SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE databasename SET OFFLINE; ALTER DATABASE databasename MODIFY FILE ( NAME = logicalfilename, FILENAME = 'new file path' ); ALTER DATABASE databasename MODIFY FILE ( NAME = logicalfilename, FILENAME = 'new file path' ); -- move the files to the new drive / directory -- set the database online ALTER DATABASE databasename SET ONLINE; -- set the database to multi user ALTER DATABASE databasename SET MULTI_USER; GO
As always there are the usual precautions to take - never do this on a production system without testing it first!!! Chris