SQL Server modifies database file and log file storage location

Source: Internet
Author: User
Tags mssqlserver

--查看当前的存放位置 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

SQL Server modifies database file and log file storage location

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.