Sql-server – Move database files if database runs

sql server

  • is possible, is there internal procedure to moving with database files if database runs, is not detached on Sql Server 2012/2008, .... EDIT.... database is online, accesible for users, services running in Native OS

  • moving from one disk to another, initialized in Windows OS as HDDs

  • or only is possible to create a replica in another SQL instace and if done then to switch between DB files

  • my question is only about how to shorten the time until the instance is unavailable (detach, copy, attach, testing of consistency)

Best Answer

If you have multiple data files for a database and you are trying to move one from one disk to another, I believe you can add new data file on the new drive to your filegroup, and then use ShrinkFile with the EmptyFile option on the file to be moved to migrate data from that file into the other files in the filegroup (SQL Server will distribute across the files automatically). The only problem with this is that you cannot do this for the first file of the database's primary filegroup, which I'm betting will be an issue for you.