SQL Server compressed database files

Source: Internet
Author: User
Tags filegroup

When the MDF or NDF file is large, the traditional DBCC SHRINKFILE command is difficult to take effect, and the current feasible solution:

    1. Create a new filegroup by rebuilding the remaining tables and specifying a clustered index to the new filegroup way to empty the source filegroup for storage space release
    2. Refer to using the following script write loop to wait for the file shrink to complete:

Big Data file Shrinking

DECLARE @BeginSize BIGINT--Original size MB

DECLARE @EndSize BIGINT--Final size MB

DECLARE @ShrinkSize BIGINT--size MB needed to shrink

DECLARE @UnitSize INT--size MB per contraction

DECLARE @Loop INT--Number of cycles

DECLARE @FileName VARCHAR (256)--Shrinking file logical name

SET @UnitSize = 512

SET @BeginSize = 239493

SET @EndSize = 164413

SET @ShrinkSize = @BeginSize-@EndSize

SET @FileName = N ' logical name of data file that needs to be shrunk '

SET @Loop = 1

While @ShrinkSize > @Loop * @UnitSize

BEGIN

SET @EndSize = @BeginSize-@Loop * @UnitSize

PRINT ' DBCC shrinkfile (' + cast (@FileName as varchar) + ', ' + cast (@EndSize as varchar) + ') beging DATETIME: ' + cast (GET DATE () as VARCHAR)

DBCC shrinkfile (@FileName, @EndSize)

PRINT ' DBCC shrinkfile (' + cast (@FileName as varchar) + ', ' + cast (@EndSize as varchar) + ') END DATETIME: ' +cast (GETDATE () as VARCHAR)

SET @Loop = @Loop + 1

END

SQL Server compressed database 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.