Shrinking the SQL Server database

Source: Internet
Author: User

If the size of the database design is too large, the database will still consume a large amount of disk resources even if large amounts of data are deleted from the database. Therefore, the database needs to be shrunk according to the actual needs of the user.

3 Ways to shrink:

1, Auto_shrink

Basic format:

ALTER DATABASE database_name SET auto_shrink on

When this option is set to ON, the database engine automatically shrinks the database with free space.

2. DBCC Shrinkdatabase

Basic format:

DBCC shrinkdatabase (' database_name ', target_percent)

This approach requires manual shrinking of the database size and is more flexible than automating shrinking the database, which shrinks the entire database.

3. DBCC Shrinkfile

Basic format:

DBCC shrinkfile (' file_name ', target_percent)

The command can shrink the specified database file, shrink the file to a size smaller than its initial creation, and reset the current size to its initial creation size. It is worth noting that the shrink statement can only shrink the database to the smallest initial file size that has been specified since the beginning of the database creation, if your database was first created with an initial size of 1024MB, and no one has ever mobilized the initial size. So sorry your data can only shrink to 1024MB, although there may be 1023MB are not actually used ...

Note: It is recommended that you do not use the auto-shrink feature frequently, preferably by disabling auto-shrinking, or by manually shrinking or dispatching the operation, shrinking every time.

Shrinking the SQL Server database

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.