• This is very easy and in fact I have a request for change for exactly this to complete this week in the organisation where I work. Follow these steps;

    • get the logical name and current path\filehame for each databases files that you wish to move. You may use this query

      select db_name(database_id), name, physical_name from sys.master_files

    • Create the statements that you will use to move the database files. Use this code as a template and fill in with the info from the query above (you need an alter statement for each database file)

      ALTER DATABASE mydb MODIFY FILE(name=logicalname,

      FILENAME='new path and drive\the originalfilename.extension')

    • Take a last check at your move statements and when happy execute them. The new paths will not take effect until the database next restarts.

      Note: Be extra careful here as sql server will accept whatever path\filename you type. If the path\filename doesn't exist when you start the database it will not come online!!

    • Take the database offline
    • copy not move the disk files to their new locations
    • bring the database online
    • once the database comes online remove the old disk files

    If for any reason the database does not come back online, don't panic. Check sys.master_files with the query above and verify the path\filename, if it's wrong change it then bring the database online.

    If all this seems too much just detach and then re attach if you find it easier 😉

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉