- --View the current storage location
- Select database_id,name,physical_name as currentlocation,state_desc,size from sys.master_files
- where database_id=db_id (N' database name ');
- --Change the location of the file to take effect the next time
- --TESTDB is the database name,
- Alter database name modify file (name = file name (does not contain suffix), filename = ' document store path ');
- Alter database name modify file (name = file name (does not contain suffix), filename = ' document store path ');
- eg.
- alter database testDb modify file ( name = testDb, filename = ' G:\SQL_DATA\testDb\testDb.mdf ');
- alter database testDb modify file ( name = testdb_log, filename = ' G:\SQL_DATA\testDb\testdb_log.ldf ' );
- --Modify the default database file storage location (immediate effect)
- EXEC Xp_instance_regwrite
- @rootkey =' HKEY_LOCAL_MACHINE ',
- @key=' software\microsoft\mssqlserver\mssqlserver ',
- @value_name =' Defaultdata ',
- @type =REG_SZ,
- @value =' E:\MSSQL_MDF\data '
- GO
- --Modify the default log file storage location <span style= "Font-family:arial, Helvetica, Sans-serif;" > (immediate effect) </span>
- EXEC Master. Xp_instance_regwrite
- @rootkey =' HKEY_LOCAL_MACHINE ',
- @key=' software\microsoft\mssqlserver\mssqlserver ',
- @value_name =' Defaultlog ',
- @type =REG_SZ,
- @value =' E:\MSSQL_MDF\log '
- GO
MSSQL Server modifies database file location This method has not been tested successfully