Solved

Shrink my database

Posted on 2011-03-08
10
323 Views
Last Modified: 2012-05-11
Database refuse to releast it's bloeted space to NTFS
My mdf file showa 600mb even after I try to scrink it. How do I scrink the database. I am expecting the "mdf" size to be under 100mb with the command below.

Thanks

dbcc shrinkfile (shop_data,76800)

--DbId      FileId      CurrentSize      MinimumSize      UsedPages      EstimatedPages
--494      1      76744      128      76736      76736
0
Comment
Question by:ruffone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35079575
try:-

USE [database_name]
GO
DBCC SHRINKDATABASE('database_name' )
GO

Open in new window

0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35079597
if you want to shrink only mdf file you may try:-

USE [database_name]
GO
DBCC SHRINKFILE ('logical_name_of_mdf_file'  , 3)
GO

Open in new window


where 3 MB is the default minimum limit for mdf file.
by default 'logical_name_of_mdf_file' is same as 'database_name'.
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35079630
if you want to shrink your database regularly then
on Database Properties-->Options set Auto Shrink=True.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 4

Author Comment

by:ruffone
ID: 35079771
That does nothing. I am becomming convinced that 600mb is the solid size of this database dispite what is in the table
0
 
LVL 5

Accepted Solution

by:
ThakurVinay earned 500 total points
ID: 35079992
As a professional DBA. you should not shirnk the database specially never shrink mdf.

also in your case its only 600MB. so i would suggest let it be.

my one cent.

HTH
Vinay
0
 
LVL 4

Author Comment

by:ruffone
ID: 35080114
I would, but that is almost the max that my host will allow on the server that I share
0
 
LVL 14

Expert Comment

by:Daniel_PL
ID: 35080164
You should never ever shrink your databases, only in rare cases poeople do that - in case of sending database to another department and db size is too big to restore it to other location. As I said it's verry rare.
I wouldn't suggest you shrinking database regularly - it's a crime ;)

http://blogs.msdn.com/b/sqlserverstorageengine/archive/2006/06/13/629059.aspx
http://www.straightpathsql.com/archives/2009/01/dont-touch-that-shrink-button/
http://blog.sqlauthority.com/2010/08/12/sql-server-shrinkdatabase-for-every-database-in-the-sql-server/

Take care,
Daniel
0
 
LVL 14

Expert Comment

by:Daniel_PL
ID: 35080181
Can you take backups of your database and store them in other location?
Maybe you can change data types in tables to store smaller rows etc. etc.
You could taking backups and then truncating tables, it depends on your vision.
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35080215
reason not to overuse shrink is that it increase fragmentation of the index and may lead to file system level fragmentation as well.

if you have specified 600MB during the creation of the database, it will not get smaller even if you use shrink. if the database grows to 800MB, by using shrink it will only be reduced to 600MB.
0
 
LVL 4

Author Closing Comment

by:ruffone
ID: 35212541
This database has seen every server since SQL 7.0. I usually just attach it to the new server. Who knows what that might have done to it over the years. So I am copping all the data into a new database and redoing the indexes. and doing some testing before I upload it to the host. Right now the new database is less than half the size of the old one. I am a bit surprised so I will have to test all the applications to be sure I am not missing anything. It is a process
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Insert parts by customer 12 53
PolyServe for SQL server 13 42
query optimization 6 22
Cannot connect to SQL express 2008 R2 installed on Server 2016 5 19
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question