Shrinking SQL Server Data File

Hi

From time to time we all need to clear up dev server, truncate the log-file and resize the bloated LDF file of the SQL Server.

How to do it?

Suppose the name of the database is Vikram

First we make the server truncate the log the next time it runs the checkpoint.
EXEC sp_dboption 'Vikram', 'trunc. log on chkpt.', 'TRUE'

Now force a check point for the database
CHECKPOINT

Now we are ready to shrink the database or transaction file or whatever.
DBCC SHRINKFILE (Vikram_Log, 200)

Now we are ready to SHRINK the database or transaction file or whatever
DBCC SHRINKFILE (Vikram_Log, 200)

And last but not the least important

Go to Enterprise manager & make sure you restrict the file size of the database

Hope this helps
Thanks
Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Posted on 9/23/2006 12:33:08 PM

Very useful -- thanks!

Posted on 10/30/2006 3:09:31 AM

Here we have so many databases in SOL server 2000
Now we are manually using this command
DBCC SHRINKFILE (POS_LOG, 2)
Where POS is the Database name
so it will reduce the ldf file size
I want a T-SQL to reduce the size of all the ldf files available in my sql server (all databases) for very week .

Posted on 3/12/2007 3:49:12 AM

I have 5 db's on the server.. how to shrink all at a time.

Also how to create batch file so it may run weekly auto.

Best Regards,

Farhan

Posted on 3/12/2007 5:09:41 AM

You can use the master database to write a script which will call the command for all the database. This should solve the problem for having to call them one by one. If you still have problem contact me at sujitdey1@gmail.com

Posted on 6/14/2007 10:49:25 PM

Can u explain me --
suppose we want to issue a book in our table and total no of books
we have 20.
when we issued book, and then books are not available
A trigger should be fired, and display a error messge..
plz help me

Posted on 6/15/2007 9:10:51 PM

Hi

Before executing the query, call the a select statement with the same where clause and check if the book is already there or not, If the book is not there then show and message do what ever you want. If the book is there than only procede with the rest of the logic

Posted on 8/28/2008 5:16:50 AM

Hi All,

We have a database which was around 259 GB. This is the datafile size - actual data in it was 211 GB, with around 48 GB free. Since it was taking much disk space, we decided to Shrink the file. So, we are running this -

DBCC SHRINKFILE('DataFile',215000)

While it is running now, we are seeing that the usage for data is decreasing. From 211 GB it has now come to 208 GB. The free space it is around 50 GB. I dont understand this behaviour. I believe ShrinkFile won't delete any data, but if that is the case, why is the size of usage decreasing? Anything going wrong here?? Please provide some ideas.

Thanks a lot,

Manoj Deshpande

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2009 Vikram Lakhotia