Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I recently truncated a table which contained 150 million records. The database files didnt shrink a little and the backup file now is 8gb (database size is 250GB even after deletion of a huge table). When I try to restore SQL wants to assign back the same 250GB even if there is no use for it.
How can I make the database smaller.
Thanks in advance.
Posted
Comments
Andy Lanng 15-Dec-15 9:35am    
You can make it smaller by deleting the contents!
I mean seriously, can't you take a backup and "archive" (delete) data that isn't used?

If you have large fields then you can compress them. This does have impact on indexing but it's surprisingly good still.

Why do you need to shrink it. Have you thought of partitioning it instead.

You may even need to redesign. I had to do this once. All the data was upside down. Everything was referenced by varchar, not ids. I managed to get it down from 40Gb to 2.5Gb and from 20Gb per year increase (exponentially growing too) to about 1.3Gb. I will still have to archive old data, but not nearly so often.
That project took me about 6 months.

1 solution

MSDN reference[^] - gives ways of doing it via SQL or SSMS.

You might also want to tidy up the transaction logs[^]
 
Share this answer
 
Comments
Vasily Tserekh 15-Dec-15 9:54am    
Is there a way to backup the database and shrink it at the same time?
CHill60 15-Dec-15 9:59am    
Er... did you read the information on the first link? "•You cannot shrink a database while the database is being backed up. Conversely, you cannot backup a database while a shrink operation on the database is in process."
What would be the point of having a shrunken backup while the main database is still in its original state?
Just do the shrink on the original (AFTER a backup)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900