Friday, August 26, 2011

T-SQL: Clear transaction logs for all databases

Works only for SQL2005

EXEC sp_MSforeachdb @command1 = "BACKUP LOG ? WITH TRUNCATE_ONLY DBCC SHRINKDATABASE( ? ) "


2 comments:

  1. Clearing out data can be done through this method. It depends on how you configure the tool.

    SEO Philippines

    ReplyDelete
  2. For one database:

    BACKUP LOG database_name WITH TRUNCATE_ONLY
    GO
    DBCC SHRINKDATABASE( database_name )
    GO

    ReplyDelete