4.5 Moving database files

Source: Internet
Author: User

4.5 Moving database files


4.5.1 Moving database files

In some scenarios, you need to move the files of the database to another path. If you allow the database to be taken offline, you can move the database files and then attach the database by detaching the database first.

You can also move a file while the database is online through a T-SQL statement, which takes effect the next time that the database comes back online. You need to use 2 parameters in the statement, the name parameter indicates the logical name of the database file, and the filename parameter indicates the path and physical file name of the moved target file.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/77/37/wKioL1ZlUC6yh7TgAAB0CfW5Qzg023.png "title=" Database properties. png "alt=" Wkiol1zluc6yh7tgaab0cfw5qzg023.png "/>


ALTER DATABASE [SQLDB01] MODIFY FILE (NAME = n ' fg2012_data ', FILENAME = n ' E:\MSSQL\Data\FG2012_data.ndf ')


When you run the preceding statement, you must ensure that the destination path already exists, or SQL Server will return the error "The specified path is not in a valid directory."

After successful execution of the above statement, the entry for the logical file name has been modified in the system directory. The new path will be used the next time the database is started.



4.5.2 Emptying data files

Before you can delete a data file, you must empty the data in the data file.


Use [AdventureWorks2014]

GO

DBCC shrinkfile (N ' adventureworks2014_2 ', emptyfile)

GO


4.5.3 Deleting data files

For an empty data file, you can delete it.


ALTER DATABASE [AdventureWorks2014] REMOVE FILE [Adventureworks2014_2]

GO


This article from "SQLServer2014 series" blog, declined reprint!

4.5 Moving database files

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.