Solved

how to shrink database

Posted on 2013-01-30
2
276 Views
Last Modified: 2013-02-25
I have 100gb SQL 2005 database FULL RECOVER MODE  and trying to shrink data size by purging some   records.
1. I have to DB live and test. Test database is a copy of live data restored to different file names. however logical name is the same for both.

BACKUP LOG TEST WITH TRUNCATE_ONLY
DBCC SHRINKFILE( Test_log Data, 2)      
log files are getting truncated
when I do QUERY ON MY TEST DB
delete from my_table
truncate MY TABLE
DBCC SHRINKFILE(LIVE_DATA, 3)

What is the safe and proper way to shrink DB
0
Comment
Question by:leop1212
2 Comments
 
LVL 40

Accepted Solution

by:
lcohan earned 500 total points
ID: 38837016
". I have to DB live and test. Test database is a copy of live data restored to different file names. however logical name is the same for both."

Can you connect to that box via SSMS? I suggest use that tool and right click the db you want to shrink, select Tasks - Shink - > Files and go from there...
0
 
LVL 24

Expert Comment

by:DBAduck - Ben Miller
ID: 38837914
The easy answer for me about Shrinking a database is DON'T.

When you shrink the database file, everything in it gets very fragmented because of the way it shrinks.  If the database will never grow again to the size you are shrinking it from, then you can shrink it and then rebuild the indexes or reorganize them.

If you are trying to get rid of data in a table, I would use TRUNCATE as it only logs the deallocation of the pages, instead of logging the delete of each row. TRUNCATE is faster.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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