Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Feb 18

Written by: Steve Gray
2/18/2010 10:20 AM  RssIcon

This is a combination of logic from 2 previous posts - this piece of code will truncate the log file size for all the databases in a SQL Server. It has been tested against SQL 2000, 2005 and 2008

--delcare variables
declare @vchrTable varchar(200),
    @vchrMsg varchar(200) 
 
--declare the cursor
DECLARE curTables CURSOR FOR 
    SELECT name from master..sysdatabases  order by 1 
 
--open the cursor
OPEN curTables 
 
--loop through the cursor lines
FETCH NEXT FROM curTables INTO @vchrTable
WHILE @@FETCH_STATUS = 0
BEGIN
    set @vchrMsg = 
'DBCC SHRINKDATABASE ( [' + @vchrTable + '] ,10);'
    print @vchrMsg
    exec (@vchrMsg) 
    
    set @vchrMsg = 
'backup log [' + @vchrTable + '] with truncate_only;'
    print @vchrMsg
    exec (@vchrMsg) 
    
    --backup log tstoday with truncate_only 
 
 FETCH NEXT FROM curTables INTO @vchrTable
END 
 
--clean up
CLOSE curTables
DEALLOCATE curTables

Tags:
Categories:
Location: Blogs Parent Separator DEVSHED Blogs Child Separator SQL
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us