syspolicy_purge_history SQL Server 代理作业可能会失败 SQL Server 2008

第一步:首先执行
use master
go
select @@servername;
select serverproperty('servername')

第二步:如果上下两个结果不一样,说明是有问题的,那么请执行下面这段代码来修复问题
if   serverproperty('servername')   <>   @@servername  
begin  
 declare   @server   sysname  
 set   @server   =   @@servername  
    exec   sp_dropserver   @server   =   @server  
    set   @server   =   cast(serverproperty('servername')   as   sysname)  
    exec   sp_addserver   @server   =   @server   ,   @local   =   'LOCAL'  
end

第三步:重新创建 syspolicy_purge_history 作业
DECLARE @jobId uniqueidentifier

-- Obtain the current job identifier that is associated with the PurgeHistory
SELECT @jobId = CAST(current_value AS uniqueidentifier)
FROM msdb.dbo.syspolicy_configuration_internal
WHERE name = N'PurgeHistoryJobGuid'

-- Delete the job identifier association in the syspolicy configuration

DELETE FROM msdb.dbo.syspolicy_configuration_internal
WHERE name = N'PurgeHistoryJobGuid'

-- Delete the offending job
EXEC msdb.dbo.sp_delete_job @job_id = @jobId

-- Re-create the job and its association in the syspolicy configuration table
EXEC msdb.dbo.sp_syspolicy_create_purge_job

你可能感兴趣的:(数据库)