DECLARE MY_CURSOR Cursor FOR
SELECT name FROM sys.databases
where name not in ('master','tempdb','model','msdb')
--開啟cursor
Open MY_CURSOR
--定義cursor裡要取出的物件
DECLARE @name VARCHAR(100)
--進入cursor
Fetch NEXT FROM MY_CURSOR INTO @name
--當陳述式失敗,或資料列超出結果集時停止迴圈
While (@@FETCH_STATUS <> -1)
BEGIN
--偵錯或加入要應用的程式碼
exec ('USE [master]
backup log '+@name+' with truncate_only
dbcc shrinkdatabase ('+@name+',1024)
declare @logName VARCHAR(100)
USE ['+@name+']
set @logName=(select name from sysfiles where status & 0x40 = 0x40)
dbcc shrinkfile (@logName,10) ')
--再到下個指標去
FETCH NEXT FROM MY_CURSOR INTO @name
END
--關閉cursor
CLOSE MY_CURSOR
--釋放cursor
DEALLOCATE MY_CURSOR
留言列表