question

nidheesh avatar image
nidheesh asked

how to reduce the size of database in sql server 2008r2

Please explain the methods to size of database in sql server 2008r2
dba
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Cyborg avatar image
Cyborg answered
you can reduce the size of the database by using DBCC SHRINKDB('DBNAME') WITH TRUNCATEONLY Command, This will shrink the database and return the unused space to OS. You can also enable autoshrink option in the database. But this is not a recommended practice. Before doing DB Shrink check how much space it is unused by sp_spaceused also make sure that you already reserved the space for the future database growth. (This information is obtained from the capacity planning) ShrinkDB and AutoGrowth (unless instant file internalization is enabled for SQL account) is highly resource consumption process especially CPU. This should not be done as a day today maintenance activity. This is recommended only after huge delete or after dropping huge tables. Usually this space is reused in the database. Also after shrinking the database your indexes may get fragmented. Please Refer [Microsoft][1], [KB Article][3] [1]: http://msdn.microsoft.com/en-us/library/ms190488.aspx [2]: http://msdn.microsoft.com/en-us/library/ms190488.aspx [3]: http://support.microsoft.com/kb/315512 [4]: http://msdn.microsoft.com/en-us/library/ms190488.aspx
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sam_mastermind avatar image sam_mastermind commented ·
Is it possible to use with truncate_only option in sql2008 r2???
0 Likes 0 ·
ThomasRushton avatar image ThomasRushton ♦♦ commented ·
As you'll see from the MS documentation that @Cyborg references, , `TRUNCATEONLY` is an option supported by `DBCC SHRINKDATABASE`.
0 Likes 0 ·
nidheesh avatar image nidheesh commented ·
is there any other method is available?.
0 Likes 0 ·
Manikreddy avatar image
Manikreddy answered
What is the purpose of shrinking the database..? do your log file is growing abnormally or have you assined more space to datafile accidentally....if log is growing better to add t-log backups to the db or shrink only the log file it will shrink only log file do not touch datafile.. Shrinking of log file is tolarable but shrinking of datafile is not a acceptable method, it will increses fragmentation in file.. you can shrink the file using below command.. DBCC shrinkfile('filename','size in MB')
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Tim avatar image
Tim answered
Unless you have just deleted a great deal of data shrinking the database might not be a good idea. @Manikreddy is correct that shrinking the data file will fragment the database. Might you really just be needing to shrink your log file? If you aren't taking regular backups of your transaction logs they will grow very large.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.