script to shink log

First switch to that database,then run this:

==================================

DECLARE @DB varchar(100)
SET @DB = DB_NAME()
BACKUP LOG @DB WITH TRUNCATE_ONLY
DBCC SHRINKDATABASE (@DB, TRUNCATEONLY )

==================================

It worked very well for me in SQL 2005, but not for 2008 any more. This is syntax for 2008

=================================

ALTER DATABASE xxxxx SET RECOVERY SIMPLE
DBCC SHRINKFILE( xxxx_log )

=================================

This works too but not very convenient:

alter database <mydb> set recovery simple
go

checkpoint
go

alter database <mydb> set recovery full
go

backup database pubs to disk = ‘c:\mydb.bak’ with init
go

dbcc shrinkfile (N’mydb_log’ , 1)
g

Advertisements
This entry was posted in SQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s