SQL Server move database or datafile

Source: Internet
Author: User

Move data or log files

1. Run the following statement.

ALTER DATABASE database_name SET OFFLINE;

2. Move the file to a new location

3. For each file you have moved, run the following statement

ALTER DATABASE database_name MODIFY FILE (name = logical_name, FILENAME = ' new_path\os_file_name ');

4. Run the following statement

ALTER DATABASE database_name SET ONLINE;

5. Verify file changes by running the following query

SELECT name, physical_name as Currentlocation, State_desc

From Sys.master_files

WHERE database_id = db_id (N ' <database_name> ')

Go

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/SQLServer/

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.