SQL数据库收缩日志

SQL数据库收缩日志


declare @name varchar(25)
declare @sql varchar(1000)
declare @logid int

DECLARE sdys cursor for select /*top 5 部分处理*/ name from master.dbo.sysdatabases

open sdys


FETCH NEXT FROM sdys   into   @name

WHILE @@FETCH_STATUS = 0
BEGIN

   if ( @name not in ('sdysdatabak')) --不需要进行日志收缩
   begin
     set @sql =' declare @logid int
                 use   ' + @name+'
                 select @logid = fileid from sysfiles where right(rtrim(filename),3) = ''ldf''

                 BACKUP LOG ' + @name+' WITH NO_LOG
                 DBCC SHRINKFILE (@logid) '

     exec(@sql)

   end

   FETCH NEXT FROM sdys   into   @name

END

CLOSE sdys
DEALLOCATE sdys

你可能感兴趣的:(数据库,日志,职场,休闲,收缩)