教会你备份数据库收缩数据库日志


教会你备份数据库收缩数据库日志:

打开SQL企业管理器,然后选择工具,查询分析器,复制下列代码到分析器中,右键选择执行
backup log Muonline with NO_LOG
backup log Muonline with TRUNCATE_ONLY
DBCC SHRINKDATABASE(Muonline)

第3种方法:
打开SQL企业管理器,然后选择工具,查询分析器,复制下列代码到分析器中,右键选择执行,执行之前,最好重新启动机器,然后立刻执行,否则会提示所有日志都在使用

SET NOCOUNT ON
DECLARE @LogicalFileName sysname,
@MaxMinutes INT,
@NewSize INT

USE muonline -- 要*作的数据库名
SELECT @LogicalFileName = 'MuOnline_log', -- 日志文件名
@MaxMinutes = 10, -- Limit on time allowed to wrap log.
@NewSize = 30 -- 你想设定的日志文件的大小(M)

-- Setup / initialize
DECLARE @OriginalSize int
SELECT @OriginalSize = size
FROM sysfiles
WHERE name = @LogicalFileName
SELECT 'Original Size of ' + db_name() + ' LOG is ' +
CONVERT(varCHAR(30),@OriginalSize) + ' 8K pages or ' +
CONVERT(varCHAR(30),(@OriginalSize*8/1024)) + 'MB'
FROM sysfiles
WHERE name = @LogicalFileName
CREATE TABLE DummyTrans
(DummyColumn char (8000) not null)

DECLARE @Counter INT,
@StartTime DATETIME,
@TruncLog varCHAR(255)
SELECT @StartTime = GETDATE(),
@TruncLog = 'BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY'

DBCC SHRINKFILE (@LogicalFileName, @NewSize)
EXEC (@TruncLog)
-- Wrap the log if necessary.
WHILE @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired
AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)
AND (@OriginalSize * 8 /1024) > @NewSize
BEGIN -- Outer loop.
SELECT @Counter = 0
WHILE ((@Counter < @OriginalSize / 16) AND (@Counter < 50000))
BEGIN -- update
INSERT DummyTrans valueS ('Fill Log')
DELETE DummyTrans
SELECT @Counter = @Counter + 1
END
EXEC (@TruncLog)
END
SELECT 'Final Size of ' + db_name() + ' LOG is ' +
CONVERT(varCHAR(30),size) + ' 8K pages or ' +
CONVERT(varCHAR(30),(size*8/1024)) + 'MB'
FROM sysfiles
WHERE name = @LogicalFileName
DROP TABLE DummyTrans
SET NOCOUNT OFF

 

 

请大家切记本站:奇迹私服 HTTP://www.218mu.com

 

◆ 更多的技术资料正在整理中,本决将努力的不断更新! ◆
站长QQ: 67254354[ 530免费私服发布网 版权所有 ]
Copyright @ 2007-2008 www.218mu.com 奇迹私服 All rights reserved.

免责声明:218mu.Com 新开奇迹私服 登载之所有信息及资源均出于传递更多信息之目的,并不意味着本站赞同其观点或证实其描述.本站所有信息均为免费发布,并非赢利及商业目的.