縮小SQL server數(shù)據(jù)庫(kù)日志另類(lèi)方法
縮小SQL server數(shù)據(jù)庫(kù)日志另類(lèi)方法:
--功能說(shuō)明:縮小數(shù)據(jù)庫(kù)日志文件
--數(shù)據(jù)庫(kù)名為abc
--------------------------------------------------------------
SET NOCOUNT ON
DECLARE @LOGICALFILENAME SYSNAME,
@MAXMINUTES INT,
@NEWSIZE INT
USE abc---要操作的數(shù)據(jù)庫(kù)
SELECT @LOGICALFILENAME = 'abc_LOG',---日志文件名
@MAXMINUTES = 10,---LIMIT ON TIME ALLOWED TO WRAP LOG.
@NEWSIZE = 1---你想設(shè)定的日志文件大小(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 @COUNT 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 NOE EXPIRED
AND @ORIGINALSIZE =(SELECT SIZE FROM SYSFILES WHERE NAME = @LOGICALFILENAME)
AND (@ORIGINALSIZE*8/1024)>@NEWSIZE
BEGIN --OUTER LOOP.
SELECT @COUNT = 0
WHILE((@COUNT<@ORIGINALSIZE/16) AND (@COUNT<50000))
BEGIN -- UPDATE
INSERT DUMMYTRANS VALUES ('FILL LOG')
DELETE DUMMYTRANS
SELECT @COUNT = @COUNT + 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
關(guān)鍵字:SQL server、數(shù)據(jù)庫(kù)、日志
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無(wú)AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解