1 --View current storage location2 SelectDatabase_id,name,physical_name ascurrentlocation,state_desc,size3 fromsys.master_files4 wheredatabase_id=db_id(N'Database name');5 6 --Change the location of the file to take effect the next time7 --TestDB is the database name,8 Alter DatabaseDatabase name Modifyfile(Name=FileName (does not contain a suffix), filename= 'File storage Path');9 Alter DatabaseDatabase name Modifyfile(Name=FileName (does not contain a suffix), filename= 'File storage Path');Ten eg. One Alter DatabaseTestDb Modifyfile(Name=TestDb, filename= 'G:\SQL_DATA\testDb\testDb.mdf'); A Alter DatabaseTestDb Modifyfile(Name=Testdb_log, filename= 'G:\SQL_DATA\testDb\testdb_log.ldf'); - - --Modify the default database file storage location (immediate effect) the EXECXp_instance_regwrite - @rootkey='HKEY_LOCAL_MACHINE', - @key='Software\microsoft\mssqlserver\mssqlserver', - @value_name='Defaultdata', + @type=REG_SZ, - @value='E:\MSSQL_MDF\data' + GO A --Modify the default log file location (immediate effect) at EXECMaster.. Xp_instance_regwrite - @rootkey='HKEY_LOCAL_MACHINE', - @key='Software\microsoft\mssqlserver\mssqlserver', - @value_name='Defaultlog', - @type=REG_SZ, - @value='E:\MSSQL_MDF\log' in GO
SQL Server modifies database file storage location