--View Current storage location Select Database_id,name,physical_name as Currentlocation,state_desc,size from Sys.master_files where Datab
ase_id=db_id (N ' database name ');
--Modify the location of the file to start the next time the--TESTDB is the database name, ALTER DATABASE name modify file (name = filename (not including suffix), filename = ' file storage path ');
ALTER DATABASE name modify file (name = filename (not including suffix), filename = ' file storage 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 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 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