嗨我在每周维护过程中使用此脚本,建议最佳方法/脚本来执行收缩日志。目前,我得到一个错误与下面的脚本收缩日志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