--查看當前的存放位置 select database_id,name,physical_name AS CurrentLocation,state_desc,size from sys.master_files where database_id=db_id(N'數據庫名'); --修改文件的存放位置下次啟動生效 --testDb為數據庫名, alter database 數據庫名 modify file ( name = 文件名(不包含後綴), filename = '文件存儲路徑'); alter database 數據庫名 modify file ( name = 文件名(不包含後綴), filename = '文件存儲路徑'); 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'); --修改默認的數據庫文件存放位置(即時生效) 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 --修改默認的日志文件存放位置<span style="font-family: Arial, Helvetica, sans-serif;">(即時生效)</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