SQL Server specifies that the initial database size cannot be shrunk when the database is created

Source: Internet
Author: User

When you create a database in SQL Server you can specify the initial size of the database file, for example, we set the size of the newly created database mydb to 1024MB

Well, the database you built will actually take up about 1024MB of disk space.

However, using the stored procedure sp_spaceused you can see that there is 1021.85 MB of space that is mydb occupied unused.

So we were wondering if we could use DBCC SHRINKDATABASE or DBCC SHRINKFILE statements to shrink unused database space

DBCC shrinkdatabase ('MyDB',ten)


But after executing the shrink statement, we found that the database size did not change the slightest ...

And be prompted after executing the Shrink statement

This means that SQL Server thinks mydb has no space to contract ... But in fact, we can see through the stored procedure sp_spaceused that mydb really has 1021.85 MB of space that is unused. The reason why the database cannot be shrunk is that the initial size specified when creating the SQL Server database cannot be shrunk, and the unused space can be shrunk by using the ALTER DATABASE statement or by re-specifying the initial size of mydb in SMSS.

Now we'll change the initial size of MyDB to 800MB in SMSs.

You can see that the size of the mydb is really around 800MB now.

And now we're going to change the initial size of mydb back to 1024MB.

Then execute DBCC SHRINKDATABASE (' MyDB ', 10), you can see that the database size becomes about 800MB, so in fact shrinkdatabase statement can only shrink the database to The smallest initial file size that has been specified since the start of the database , if your database was first created with a size of 1024MB, and no one has ever been transferred to a size so sorry, the smallest of your data can only shrink to 1024MB. Although it is possible that 1023MB is not actually used ...

SQL Server specifies that the initial database size cannot be shrunk when the database is created

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.