嗨我在每週維護過程中使用此腳本,建議最佳方法/腳本來執行收縮日誌。目前,我得到一個錯誤與下面的腳本收縮日誌SQL2008中的所有用戶數據庫
declare @s nvarchar(4000)
set @s= '
if ''?'' not in (''tempdb'',''master'',''model'',''msdb'')
begin
use [?]
Alter database [?] SET Recovery simple
end '
exec sp_msforeachdb @s
set @s= '
if ''?'' not in (''tempdb'',''master'',''model'',''msdb'')
begin
use [?]
Declare @LogFileLogicalName sysname
select @LogFileLogicalName=Name from sys.database_files where Type=1
DBCC Shrinkfile(@LogFileLogicalName,1)
end'
exec sp_msforeachdb @s
錯誤說明:
ShrinkLog Execute SQL Task Description: Executing the query "declare @s nvarchar(4000) set @s= ' ..." failed with the following error: "Option 'RECOVERY' cannot be set in database 'tempdb'. Cannot shrink log file 2 (DBServices_Log) because total number of logical log files cannot be fewer than 2. DBCC execution completed. If DBCC printed error messages, contact your system administrator.
注:我在我的劇本避免tempdb數據庫(所有系統DB),但錯誤消息顯示tempdb的?
當您在普通查詢窗口而不是計劃作業中手動運行時,是否出現錯誤? – Pondlife 2010-10-06 11:27:55
它計劃運行通過SQL ServerAgent作業 – rmdussa 2010-10-06 22:26:29