Reclaim space after dropping a table

Lily June 101 Reputation points
2021-12-01T08:56:21.627+00:00

I have a table in my DB that is 30GB in size.

The disk space is not change once I drop the table , how can I do.

Please help advice.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,299 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,519 questions
0 comments No comments
{count} votes

Accepted answer
  1. Olaf Helper 39,026 Reputation points
    2021-12-01T09:06:11.45+00:00

    SQL Server never shrinks a database file on it's own, because it's an expensive I/O operation.
    You can shrink the database (file) manually with

    DBCC SHRINKDATABASE (Transact-SQL)
    DBCC SHRINKFILE (Transact-SQL)

    Note: Shrinking will cause index fragmentation and that effects query performance.


2 additional answers

Sort by: Most helpful
  1. Seeya Xi-MSFT 16,411 Reputation points
    2021-12-01T09:22:23.483+00:00

    Hi @Lily June ,

    The drop table table will release the data space to the data file. That is, make part of the occupied data space free
    That requires shrinking the database or file.
    In order to reduce the shrink time, you can try DBCC SHRINKFILE first.
    After shrinking, you can rebuild the index for the fragmentation problem.

    Best regards,
    Seeya


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Tom Phillips 17,711 Reputation points
    2021-12-02T17:46:55.777+00:00

    Just to be clear.

    When you delete data from the database, the space used by that data is flagged as "free" inside the database file and is available for use by new data rows. The physical file never gets reduced unless you manually shrink the file/database.