SQL Server deletes filegroups and files

Source: Internet
Author: User
Tags filegroup

File and filegroup deletion, if because the previous partition scheme is unreasonable, need to cancel partition, or partition in another way, you need to involve the deletion of files and filegroups, if not mastered the correct steps, sometimes can not be deleted, will prompt you "file is not empty, cannot delete" or "filegroup is not empty, Cannot delete "and so on, if do not know the skill, will be very depressed!" I have experienced such a depressed! Baidu also did not find the correct answer.
1, the deletion of files: first to clear the file in the data, delete before the data must remember to back up, you can copy the data to another table, and then execute:

DBCC shrinkfile (FileName, emptyfile);

After the contents of the file are deleted, the delete file command is executed, DatabaseName represents the data name, and filename indicates the file name:

ALTERDATABASE[DataBaseName] REMOVE FILE FileName;

2. File group deletion:
When the file group file is deleted, as normal understanding, you should be able to delete the filegroup directly, it is not practical, you can not delete filegroups.
Because there are a few things that depend on filegroups, one is a partitioning scheme, and the other is a partitioned table that uses the partitioning scheme.
Therefore, to delete a partition scheme, you can delete a filegroup. But before you delete a partition scheme, change the partition table that depends on it so that it does not depend on it.
This is mainly to change the partition table partition column, so that it does not use partition scheme, if it does not change, in the table data has been backed up, you can directly delete the table to resolve.
Then delete the partition table scheme, and finally you can delete the filegroup directly.
Summarize the previous removal process:
1, modify the partition table so that it does not depend on the partition scheme.
2. Delete the partition scheme (dependent on the filegroup to be deleted).

DROPPARTITION SCHEME [Part_func_scheme_Name]

3. Delete file groups directly.

ALTERDATABASE[DataBaseName] REMOVE FILEGROUP [FGName]


DatabaseName represents the data name, and Fgname represents the filegroup name.

SQL Server deletes filegroups and files

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.