sql-serverfilegroup

The sql server size file doesn't decrease when i delete my records


I have a table called test i insert 40000 records in it ,I split my database file into two file groups like this :

enter image description here

The size of both files based on round robin algorithm increased 160 mb as you can see . after this i delete the data in my table .but the size of both file (FileGroup) remains on 160 mb .Why ?


Solution

  • This is because SQL Server is assuming that if your database got that large once, it is likely it will need to do so again. To save having to go through the overhead of requesting space from the operating system each time SQL Server wants to use some more disk space, it will simply hold on to what it has and fill it back up as required unless you manually issue a SHRINK DATABASE command.

    Due to this, using shrink is generally considered a bad idea, unless you are very confident your database will not need that space at some point in the future.