SQL Server 2012 notes Sharing-54: Database File Management 1

Source: Internet
Author: User

(i) Add a file

Can be executed online, without affecting the database usage.

650) this.width=650; "title=" border-top:0px "style="; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" src= "Http://img1.51cto.com/attachment/201407/11/639838_1405121039d3h9.png" "542" height= "484"/>


After the add is complete.


650) this.width=650; "title=" "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" "src=" Http://img1.51cto.com/attachment/201407/11/639838_1405121042o2KC.png " "644" height= "302"/>


It can also be added in the form of a script.


650) this.width=650; "title=" border-top:0px "style="; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" src= "Http://img1.51cto.com/attachment/201407/11/639838_140512104584Rg.png" "644" height= "166"/>

(ii) Deletion of documents


can be executed online without affecting database usage.

Successful execution occurs only if the actual space used in the file is empty.

(iii) Move files to different disk paths


The database must be taken offline, causing the database to be temporarily unavailable

Detailed reference: http://msdn.microsoft.com/zh-cn/library/ms345483.aspx

To move the data or log files as part of a planned relocation, follow these steps:

1. Run the following statement.

ALTER DATABASE database_name SET OFFLINE;

2. Move the file to a new location.

3. For each file that 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 the file changes by running the following query.

SELECT name, physical_name as Currentlocation, state_descfrom sys.master_fileswhere database_id = db_id (N ' <database_ Name> ');
is a process that moves the database from the default location to the data folder of the C drive.
650) this.width=650; "title=" "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px;  padding-right:0px "border=" 0 "alt=" src= "Http://img1.51cto.com/attachment/201407/11/639838_1405121047MPBj.png" "644" height= "153"/>

You can see that the move was successful by querying the following statement.
650) this.width=650; "title=" style= "border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px;  padding-right:0px "border=" 0 "alt=" src= "Http://img1.51cto.com/attachment/201407/11/639838_1405121048Zy8f.png" "644" height= "242"/>
It can also be viewed through the graphical interface.
650) this.width=650; "title=" to "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; border-left:0px;  padding-right:0px "border=" 0 "alt=" src= "Http://img1.51cto.com/attachment/201407/11/639838_1405121050MBjD.png" "644" height= "279"/>
=================================================================

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.