Cleaning after Deleting records

Jacek Kaczyński 0 Reputation points
2023-08-08T07:38:28.58+00:00

Hello, i have question. Does a query that would delete the remnants in the database after deleting records exist? If so, what does it look like?

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 31,391 Reputation points
    2023-08-08T08:48:02.15+00:00

    When you delete records using the DELETE command, the space consumed by those records isn't necessarily returned to the operating system immediately. The space is marked as free and will be reused for new records, but if you want to release the unused space to the operating system, you can use the DBCC SHRINKDATABASE or DBCC SHRINKFILE command.

    For a specific file:

    
    DBCC SHRINKFILE (YourLogicalFileName, target_size_in_MB)
    
    

    For the entire database:

    
    DBCC SHRINKDATABASE (YourDatabaseName, target_percentage)
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.