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!
Aug 4

Written by: Steve Gray
8/4/2010 8:46 AM  RssIcon

This code was written for SQL 2000, but should run on later versions with little modification. I think that ‘sysdatabases’ might need to be changes to ‘sys.databases’

This will loop through all the dbs on a server with a database id > 4, which on SQL 2000 will eliminate the system dbs. It will truncate the logs for all the databases

DECLARE @db varchar(255)
declare @sql varchar(200)
DECLARE curName CURSOR LOCAL FAST_FORWARD FOR 
    select name
        from sysdatabases
        where dbid > 4
        order by dbid
        
OPEN curName
WHILE 1=1 
BEGIN
    FETCH NEXT FROM curName INTO @db
    if @@fetch_status <> 0 begin
        break
    end 
    set @sql = 'backup log ' + @db + ' with truncate_only'
    print @sql
    exec (@sql)
    set @sql = 'DBCC SHRINKDATABASE ( ' + @db + ' ,10)'
    print @sql
    exec (@sql)
END
CLOSE curName
DEALLOCATE curName 

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