CREATE TABLE [dbo].[ca_agent]
(
[last_run_date] [int] NULL,
[object_uuid] [binary] (16) NOT NULL,
[agent_version] [nvarchar] (32) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[description] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[prev_manager] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[server_uuid] [binary] (16) NULL,
[agent_area] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[agent_file_id] [nvarchar] (36) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[agent_type] [int] NULL,
[creation_user] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[creation_date] [int] NULL,
[last_update_user] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[last_update_date] [int] NULL,
[version_number] [int] NULL CONSTRAINT [DF__ca_agent__versio__40257DE4] DEFAULT ((0)),
[class_id] [int] NULL,
[domain_id] [int] NULL,
[unit_id] [int] NULL,
[agent_name] [nvarchar] (192) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[boot_server_uuid] [binary] (16) NULL,
[registration_type] [int] NULL,
[auto_server_version] [int] NULL CONSTRAINT [DF__ca_agent__auto_s__4119A21D] DEFAULT ((0)),
[auto_rep_version] [timestamp] NULL,
[agent_ref_count] [int] NULL,
[agent_lock] [int] NULL,
[derived_status_am] [int] NULL CONSTRAINT [DF__ca_agent__derive__420DC656] DEFAULT ((0)),
[derived_status_sd] [int] NULL CONSTRAINT [DF__ca_agent__derive__4301EA8F] DEFAULT ((0)),
[derived_status_rc] [int] NULL CONSTRAINT [DF__ca_agent__derive__43F60EC8] DEFAULT ((0)),
[derived_status_babld] [int] NULL CONSTRAINT [DF__ca_agent__derive__44EA3301] DEFAULT ((0)),
[ip_address] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CS_AS NULL,
[proc_os_id] [int] NULL,
[user_def1] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[user_def2] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[user_def3] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[user_def4] [nvarchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[trustlevel] [int] NULL CONSTRAINT [ca_agent_tl] DEFAULT ((5)),
[origin] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[derived_status_pt] [int] NULL CONSTRAINT [DF__ca_agent__derive__02A2DC18] DEFAULT ((0)),
[derived_status_pt_as] [int] NULL CONSTRAINT [DF__ca_agent__derive__03970051] DEFAULT ((0)),
[derived_status_pt_av] [int] NULL CONSTRAINT [DF__ca_agent__derive__048B248A] DEFAULT ((0)),
[derived_status_pt_ip] [int] NULL CONSTRAINT [DF__ca_agent__derive__057F48C3] DEFAULT ((0)),
[tenant_id] [binary] (16) NULL
) ON [PRIMARY]
GO
CREATE trigger r_am_proc_delete_unit
on ca_agent
instead of delete
as
begin
declare @object_uuid binary(16) ;
declare @agent_type integer;
declare @unit_id integer;
declare @domain_id integer;
DECLARE r_am_proc_delete_unit_cur CURSOR
FOR SELECT object_uuid, agent_type, unit_id, domain_id
FROM deleted
OPEN r_am_proc_delete_unit_cur
FETCH NEXT FROM r_am_proc_delete_unit_cur INTO @object_uuid, @agent_type, @unit_id, @domain_id
WHILE @@FETCH_STATUS = 0
BEGIN
execute ca_am_update_agent_derived @object_uuid
execute am_proc_delete_unit @object_uuid, @agent_type, @unit_id, @domain_id
delete from ca_agent where object_uuid=@object_uuid
FETCH NEXT FROM r_am_proc_delete_unit_cur INTO @object_uuid, @agent_type, @unit_id, @domain_id
END
CLOSE r_am_proc_delete_unit_cur
DEALLOCATE r_am_proc_delete_unit_cur
end;
GO
CREATE trigger r_del_agent
on ca_agent
after delete
as
begin
declare @old_object_uuid as binary(16);
declare cur_cl cursor for
select object_uuid from deleted
open cur_cl;
fetch cur_cl into @old_object_uuid;
while @@fetch_status = 0
begin
execute p_integrity_d_agent @old_object_uuid ;
fetch cur_cl into @old_object_uuid;
end;
close cur_cl;
deallocate cur_cl;
end
GO
CREATE trigger r_u_ca_agent
on ca_agent
after update
as
if update(description)
begin
declare @object_uuid binary(16);
declare @description nvarchar(255);
declare @domain_id integer;
declare cursor_ca_agent cursor local for
select object_uuid, description, domain_id from inserted
open cursor_ca_agent;
fetch next from cursor_ca_agent into @object_uuid, @description, @domain_id;
while @@fetch_status = 0
begin
execute p_urc_ab_ca_agent_updated @object_uuid, @description, @domain_id;
fetch next from cursor_ca_agent into @object_uuid, @description, @domain_id;
end;
close cursor_ca_agent;
deallocate cursor_ca_agent;
end
GO
CREATE trigger r_upd_verno_agent
on ca_agent
after update
as
declare @old_verno as int;
declare @new_verno as int;
begin
if update (version_number)
begin
DECLARE mycur CURSOR
FOR select deleted.version_number, inserted.version_number from inserted, deleted
OPEN mycur
FETCH NEXT FROM mycur INTO @old_verno , @new_verno ;
WHILE @@FETCH_STATUS = 0
BEGIN
execute p_integrity_version_number @old_verno , @new_verno ;
FETCH NEXT FROM mycur INTO @old_verno , @new_verno ;
END
CLOSE mycur
DEALLOCATE mycur
end;
end;
GO
SET QUOTED_IDENTIFIER OFF
GO
create trigger rule_del_agent_check_busr
on ca_agent
after delete
as
begin
declare @_object_uuid binary(16);
declare lst_obj_uuid cursor for
select object_uuid from deleted;
open lst_obj_uuid;
fetch from lst_obj_uuid into @_object_uuid;
while @@fetch_status = 0
begin
execute backup_p_del_agent @_object_uuid;
fetch from lst_obj_uuid into @_object_uuid;
end;
close lst_obj_uuid;
deallocate lst_obj_uuid;
end;
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger t_ca_agent_status_rc_insert
on ca_agent
after insert
as
begin
declare @l_func nvarchar(40)
declare @l_modified_uuid binary(16)
set @l_func = 't_ca_agent_status_rc_insert'
set @l_modified_uuid = (select object_uuid from INSERTED);
exec p_ca_rc_agent_status_update @l_modified_uuid
end;
GO
create trigger t_ca_agent_status_rc_update
on ca_agent
after update
as
if update ( last_run_date )
begin
declare @l_func nvarchar(40)
declare @l_modified_uuid binary(16)
set @l_func = 't_ca_agent_status_rc_update'
set @l_modified_uuid = (select object_uuid from INSERTED);
exec p_ca_rc_agent_status_update @l_modified_uuid
end;
GO
CREATE TRIGGER t_u_ca_agent ON dbo.ca_agent
FOR UPDATE
AS
if update (last_run_date)
begin
update ca_discovered_hardware
set discovery_changes_switch = 1
where dis_hw_uuid in (select object_uuid from inserted)
and discovery_changes_switch <> 1
end
GO
create trigger uam_trg_ca_agent_insert
on ca_agent
after insert
as
begin
declare @object_uuid binary(16) ;
declare @agent_type integer;
DECLARE am_cur CURSOR
FOR SELECT object_uuid,agent_type
FROM inserted
OPEN am_cur
FETCH NEXT FROM am_cur INTO @object_uuid,@agent_type
WHILE @@FETCH_STATUS = 0
BEGIN
IF(@agent_type=1 OR @agent_type=2)
BEGIN
EXECUTE ca_am_update_agent_derived @object_uuid
END
FETCH NEXT FROM am_cur INTO @object_uuid,@agent_type
END
CLOSE am_cur
DEALLOCATE am_cur
end
GO
create trigger uam_trg_ca_agent_update
on ca_agent
after update
as
if UPDATE(last_run_date)
begin
declare @object_uuid binary(16) ;
declare @agent_type integer;
DECLARE am_cur CURSOR
FOR SELECT object_uuid,agent_type
FROM deleted
OPEN am_cur
FETCH NEXT FROM am_cur INTO @object_uuid,@agent_type
WHILE @@FETCH_STATUS = 0
BEGIN
IF(@agent_type=1 OR @agent_type=2)
BEGIN
execute ca_am_update_agent_derived @object_uuid
END
FETCH NEXT FROM am_cur INTO @object_uuid,@agent_type
END
CLOSE am_cur
DEALLOCATE am_cur
end
GO
CREATE trigger usd_trg_d_agent_usd_rel
on ca_agent
for delete as
declare
@counted int
begin
set @counted = (select count(*) from deleted where agent_type = 1 or agent_type = 4)
if(@counted = 0)
begin
return
end
set @counted = (select count(*)
from usd_v_nr_of_active_applics aa, deleted d
where aa.target = d.object_uuid
and activity <> 0x00000000000000000000000000000000)
if(@counted > 0)
begin
raiserror('Error 9011: Cannot remove the computer because of active Software Delivery jobs', 16, 1 )
rollback transaction
return
end
select act.objectid, act.actproc into #activity
from usd_applic a, usd_activity act, deleted d
where a.activity = act.objectid
and a.target = d.object_uuid
set @counted = (select count(*) from #activity)
if(@counted = 0)
begin
delete from usd_link_grp_cmp from deleted where comp = object_uuid
delete from usd_applic from deleted where target = object_uuid
delete from usd_target from deleted where objectid = object_uuid
update usd_class_version set modify_version = modify_version + 1
where name = 'link_grp_cmp'
or name = 'usd_applic'
or name = 'target'
return
end
delete from usd_link_grp_cmp from deleted where comp = object_uuid
delete from usd_link_act_cmp from deleted where comp = object_uuid
delete from usd_link_jc_srv from deleted where server = object_uuid
delete from usd_link_act_inst
from deleted d inner join usd_applic a on d.object_uuid = a.target
where usd_link_act_inst.installation = a.objectid
delete from usd_target from deleted where objectid = object_uuid
update usd_class_version set modify_version = modify_version + 1
where name = 'link_grp_cmp'
or name = 'link_act_cmp'
or name = 'link_jc_srv'
or name = 'link_act_inst'
or name = 'target'
delete from usd_applic
from deleted
where target = object_uuid
select objectid into #activity_deleted
from #activity
where objectid not in (select appl.activity
from usd_applic appl, #activity act
where appl.activity = act.objectid)
delete from #activity
from #activity_deleted ad
where #activity.objectid = ad.objectid
update usd_class_version set modify_version = modify_version + 1 where name = 'applic'
create table #actcount(oid binary(16), totcnt int default 0, waitcnt int default 0, actcnt int default 0, okcnt int default 0, errcnt int default 0,
totrencnt int default 0, waitrencnt int default 0, actrencnt int default 0, okrencnt int default 0, errrencnt int default 0)
create table #interm_count(oid binary(16), cnt int, counterid int)
insert into #actcount(oid, totcnt)
select act.objectid, count(*)
from usd_applic app, #activity act
where app.activity = act.objectid
group by act.objectid
insert into #interm_count(oid, cnt, counterid)
select act.objectid, count(*), 1
from usd_applic appv, #activity act
where appv.activity = act.objectid
and renewstatus <> 0
group by act.objectid
update #actcount set totrencnt = cnt
from #interm_count
where #actcount.oid = #interm_count.oid and #interm_count.counterid = 1
insert into #interm_count(oid, cnt, counterid)
select act.objectid, count(*) cnt, 2
from usd_v_nr_of_waiting_applics appv, #activity act
where appv.activity = act.objectid
group by act.objectid
update #actcount set waitcnt = cnt
from #interm_count
where #actcount.oid = #interm_count.oid and #interm_count.counterid = 2
insert into #interm_count(oid, cnt, counterid)
select act.objectid, count(*) cnt, 3
from usd_v_nr_of_renew_wait_applics appv, #activity act
where appv.activity = act.objectid
group by act.objectid
update #actcount set waitrencnt = cnt
from #interm_count
where #actcount.oid = #interm_count.oid and #interm_count.counterid = 3
insert into #interm_count(oid, cnt, counterid)
select act.objectid, count(*) cnt, 4
from usd_v_nr_of_active_applics appv, #activity act
where appv.activity = act.objectid
group by act.objectid
update #actcount set actcnt = cnt
from #interm_count
where #actcount.oid = #interm_count.oid and #interm_count.counterid = 4
insert into #interm_count(oid, cnt, counterid)
select act.objectid, count(*) cnt, 5
from usd_v_nr_of_renew_active_applics appv, #activity act
where appv.activity = act.objectid
group by act.objectid
update #actcount set actrencnt = cnt
from #interm_count
where #actcount.oid = #interm_count.oid and #interm_count.counterid = 5
insert into #interm_count(oid, cnt, counterid)
select act.objectid, count(*) cnt, 6
from usd_v_nr_of_ok_applics appv, #activity act
where appv.activity = act.objectid
group by act.objectid
update #actcount set okcnt = cnt
from #interm_count
where #actcount.oid = #interm_count.oid and #interm_count.counterid = 6
insert into #interm_count(oid, cnt, counterid)
select act.objectid, count(*) cnt, 7
from usd_v_nr_of_renew_ok_applics appv, #activity act
where appv.activity = act.objectid
group by act.objectid
update #actcount set okrencnt = cnt
from #interm_count
where #actcount.oid = #interm_count.oid and #interm_count.counterid = 7
update #actcount set errcnt = totcnt - waitcnt - actcnt - okcnt
update #actcount set errrencnt = totrencnt - waitrencnt - actrencnt - okrencnt
update usd_activity set
waitingcnt = waitcnt,
activecnt = actcnt,
okcnt = #actcount.okcnt,
errorcnt = errcnt,
waitingrenewcnt = waitrencnt,
activerenewcnt = actrencnt,
okrenewcnt = okrencnt,
errorrenewcnt = errrencnt
from #actcount
where objectid = oid
update usd_activity set state = 1
from #actcount
where objectid = oid
and #actcount.actcnt > 0
update usd_activity set state = 0
from #actcount
where objectid = oid
and #actcount.actcnt = 0
and #actcount.waitcnt > 0
update usd_activity set state = 2
from #actcount
where objectid = oid
and #actcount.actcnt = 0
and #actcount.waitcnt = 0
and #actcount.totcnt = #actcount.okcnt
and state <> 7
update usd_activity set state = 3
from #actcount
where objectid = oid
and #actcount.actcnt = 0
and #actcount.waitcnt = 0
and #actcount.totcnt <> #actcount.okcnt
and state <> 7
update usd_activity set renewstate = 1
from #actcount
where objectid = oid
and #actcount.actrencnt > 0
and renewstate <> 8
update usd_activity set renewstate = 0
from #actcount
where objectid = oid
and #actcount.actrencnt = 0
and #actcount.waitrencnt > 0
and renewstate <> 8
update usd_activity set renewstate = 8
from #actcount
where objectid = oid
and #actcount.actrencnt = 0
and #actcount.waitrencnt = 0
and #actcount.okrencnt+#actcount.errrencnt+#actcount.actrencnt+#actcount.waitrencnt = 0
and renewstate <> 8
update usd_activity set renewstate = 3
from #actcount
where objectid = oid
and #actcount.actrencnt = 0
and #actcount.waitrencnt = 0
and #actcount.okrencnt+#actcount.errrencnt+#actcount.actrencnt+#actcount.waitrencnt <> 0
and #actcount.errrencnt > 0
and renewstate <> 8
update usd_activity set renewstate = 2
from #actcount
where objectid = oid
and #actcount.actrencnt = 0
and #actcount.waitrencnt = 0
and #actcount.okrencnt+#actcount.errrencnt+#actcount.actrencnt+#actcount.waitrencnt <> 0
and #actcount.errrencnt = 0
and #actcount.actcnt = 0
and #actcount.waitcnt = 0
and #actcount.totrencnt = #actcount.errcnt
and renewstate <> 8
update usd_activity set renewstate = 50
from #actcount
where objectid = oid
and #actcount.actrencnt = 0
and #actcount.waitrencnt = 0
and #actcount.okrencnt+#actcount.errrencnt+#actcount.actrencnt+#actcount.waitrencnt <> 0
and #actcount.errrencnt = 0
and #actcount.actcnt = 0
and #actcount.waitcnt = 0
and #actcount.totrencnt <> #actcount.errcnt
and renewstate <> 8
update usd_activity set renewstate = 50
from #actcount
where objectid = oid
and #actcount.actrencnt = 0
and #actcount.waitrencnt = 0
and #actcount.okrencnt+#actcount.errrencnt+#actcount.actrencnt+#actcount.waitrencnt <> 0
and #actcount.errrencnt = 0
and (#actcount.actcnt <> 0 or #actcount.waitcnt <> 0)
and renewstate <> 8
update usd_activity set permmask = permmask | 2
from #activity b
where usd_activity.objectid = b.objectid
and state in (0,2,3)
update usd_activity set permmask = permmask & ~2
from #activity b
where usd_activity.objectid = b.objectid
and state not in (0,2,3)
update usd_activity set usd_activity.permmask = usd_activity.permmask | 8
from #activity b, usd_applic appl
where usd_activity.objectid = b.objectid
and usd_activity.state = 0
and appl.activity = b.objectid
update usd_activity set permmask = permmask & ~8
from #activity b
where usd_activity.objectid = b.objectid
and usd_activity.state <> 0
select act.objectid as actoid, rsw.objectid as rswoid into #actrsw
from #activity act,usd_actproc ap, usd_rsw rsw
where act.actproc = ap.objectid
and rsw.objectid = ap.rsw
insert into #interm_count(oid, cnt, counterid)
select rsw.rswoid oid, count(ap.objectid) cnt, 9
from usd_actproc ap, #actrsw rsw
where ap.rsw = rsw.rswoid
and ap.task = 1
and (ap.includedproc = 0 or ap.includedproc = 1 or ap.includedproc = 3)
group by rsw.rswoid
delete from #actrsw
where rswoid not in (select oid from #interm_count where counterid = 9)
select objectid, activity, actproc, target into #act_valid_for_rec
from usd_applic
where(renewstatus = 0
or renewstatus = 10)
and actproc <> 0x00000000000000000000000000000000
and status = 10
and task = 0x00000001
and errorcause in (228001, 228002, 228003, 228004, 228005)
and objectid in (select
case
when AP.firstrenew <> 0x00000000000000000000000000000000 then AP.firstrenew
else AP.objectid
end as objid
from usd_applic AP, #activity ACT
where AP.activity = ACT.objectid)
delete from #act_valid_for_rec
where #act_valid_for_rec.activity not in (select #actrsw.actoid from #actrsw)
select AP.objectid, AP.activity, AP.target, AP.actproc into #act_not_valid_for_rec
from usd_applic AP, #act_valid_for_rec AVFR
where AP.target = AVFR.target
and AP.actproc = AVFR.actproc
and (
(AP.task = 0x01 and AP.status != 10 and AP.status != 15 and AP.status != 16) or
(AP.task = 0x10 and AP.status != 5 and AP.status != 6)
)
and AP.uninstallstate <> 2
and (AP.status = 9 or AP.status = 4)
delete from #act_valid_for_rec
from #act_not_valid_for_rec
where #act_valid_for_rec.target = #act_not_valid_for_rec.target
and #act_valid_for_rec.actproc = #act_not_valid_for_rec.actproc
select a.installation into #ongoing_uninstall_appl
from usd_applic a, #act_valid_for_rec avfr
where installation = avfr.objectid
and a.installation <> a.objectid
and a.task = 0x02
and status <> 10
and status <> 5
delete from #act_valid_for_rec
from #ongoing_uninstall_appl
where #act_valid_for_rec.objectid = #ongoing_uninstall_appl.installation
update usd_activity set permmask = permmask | 4
from #act_valid_for_rec avfr
where usd_activity.objectid = avfr.activity
and state in (3,1)
update usd_activity set permmask = permmask & ~4
from #act_valid_for_rec avfr
where usd_activity.objectid = avfr.activity
and state not in (3,1)
update usd_activity set permmask = permmask & ~4
from #activity
where #activity.objectid not in (select activity from #act_valid_for_rec)
and usd_activity.objectid = #activity.objectid
update usd_activity set version = version + 1
from #activity
where usd_activity.objectid = #activity.objectid
delete from usd_activity from #activity_deleted ad where usd_activity.objectid = ad.objectid
delete from usd_link_jc_act from #activity_deleted ad where activity = ad.objectid
update usd_class_version set modify_version = modify_version + 1 where name = 'link_jc_act'
update usd_class_version set modify_version = modify_version + 1 where name = 'activity'
select distinct JCV.objectid as jcvoid, JC.objectid as jcoid into #jcview_jc
from usd_jcappgr APG, usd_jcview JCV, usd_job_cont JC, deleted d
where APG.jobtarget = d.object_uuid
and APG.jobcontview = JCV.objectid
and JC.objectid = JCV.jobcont
delete from usd_jcappgr from deleted where jobtarget = object_uuid
update usd_class_version set modify_version = modify_version + 1 where name = 'jcappgr'
select jcvoid, jcoid into #jcview_jc_deleted
from #jcview_jc
where jcvoid not in (select japg.jobcontview
from usd_jcappgr japg, #jcview_jc jv
where japg.jobcontview = jv.jcvoid)
delete from #jcview_jc
from #jcview_jc_deleted jjd
where #jcview_jc.jcvoid = jjd.jcvoid
update usd_class_version set modify_version = modify_version + 1 where name = 'jcappgr'
create table #jcvcount(jcvoid binary(16), waitcnt int default 0, actcnt int default 0, okcnt int default 0, errcnt int default 0,
waitrencnt int default 0, actrencnt int default 0, okrencnt int default 0, errrencnt int default 0)
insert into #jcvcount(jcvoid)
select distinct jcv.jcvoid
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 17
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and jobstatus = 0
group by jcv.jcvoid
update #jcvcount set waitcnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 17
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 10
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and jobstatus = 1
group by jcv.jcvoid
update #jcvcount set actcnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 10
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 11
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and jobstatus = 2
group by jcv.jcvoid
update #jcvcount set okcnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 11
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 12
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and jobstatus = 3
group by jcv.jcvoid
update #jcvcount set errcnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 12
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 13
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and renewedjobstatus = 0
group by jcv.jcvoid
update #jcvcount set waitrencnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 13
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 14
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and renewedjobstatus = 1
group by jcv.jcvoid
update #jcvcount set actrencnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 14
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 15
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and renewedjobstatus = 2
group by jcv.jcvoid
update #jcvcount set okrencnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 15
insert into #interm_count(oid, cnt, counterid)
select jcv.jcvoid, count(*) cnt, 16
from usd_jcappgr jcap, #jcview_jc jcv
where jcap.jobcontview = jcv.jcvoid
and renewedjobstatus = 3
group by jcv.jcvoid
update #jcvcount set errrencnt = cnt
from #interm_count
where #jcvcount.jcvoid = #interm_count.oid and #interm_count.counterid = 16
update usd_jcview set
waitingcnt = waitcnt,
activecnt = actcnt,
okcnt = #jcvcount.okcnt,
errorcnt = errcnt,
waitingrenewcnt = waitrencnt,
activerenewcnt = actrencnt,
okrenewcnt = okrencnt,
errorrenewcnt = errrencnt
from #jcvcount
where objectid = jcvoid
delete from usd_jcview from #jcview_jc_deleted where objectid = jcvoid
delete from usd_link_jc from #jcview_jc_deleted where jcparent = jcoid
delete from usd_link_jc from #jcview_jc_deleted where jcchild = jcoid
delete from usd_job_cont from #jcview_jc_deleted where objectid = jcoid
update usd_class_version set modify_version = modify_version + 1
where name = 'link_jc'
or name = 'job_cont'
end
GO
CREATE trigger usd_trg_d_ca_agent_tbl_ver
on ca_agent
for delete as
declare
@agent_type int
begin
set @agent_type = (select top 1 agent_type from inserted)
exec usd_proc_u_tbl_ver 0, -1, @agent_type, 40
end
GO
create trigger usd_trg_u_ca_agent
on ca_agent
for update as
begin
if update(last_run_date)
begin
update ca_agent set derived_status_sd = vts.object_status
from inserted, usd_v_target_status vts
where ca_agent.object_uuid = inserted.object_uuid
and inserted.object_uuid = vts.object_uuid
end
end
GO
CREATE trigger usd_trg_u_ca_agent_tbl_ver
on ca_agent
for update as
declare
@agent_type int
begin
if update(creation_user) or update(agent_name) or update(ip_address) or update(creation_date) or update(last_run_date) or update(registration_type) or update(agent_type) or update(proc_os_id) or update(description) or update(prev_manager) or update(agent_ref_count)
begin
set @agent_type = (select top 1 agent_type from inserted)
exec usd_proc_u_tbl_ver 0, -1, @agent_type, 40
end
end
GO
ALTER TABLE [dbo].[ca_agent] ADD CONSTRAINT [XPKca_agent] PRIMARY KEY CLUSTERED ([object_uuid]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [ca_agent_idx0] ON [dbo].[ca_agent] ([agent_type]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [ca_agent_idx1] ON [dbo].[ca_agent] ([unit_id], [domain_id]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ca_agent] ADD CONSTRAINT [$ca_ag_r0000086400000000] FOREIGN KEY ([server_uuid]) REFERENCES [dbo].[ca_server] ([server_uuid])
GO
ALTER TABLE [dbo].[ca_agent] ADD CONSTRAINT [FKca_agent_tnt] FOREIGN KEY ([tenant_id]) REFERENCES [dbo].[ca_tenant] ([id])
GO
GRANT SELECT ON [dbo].[ca_agent] TO [aiadmin]
GRANT SELECT ON [dbo].[ca_agent] TO [ca_itrm_group]
GRANT INSERT ON [dbo].[ca_agent] TO [ca_itrm_group]
GRANT DELETE ON [dbo].[ca_agent] TO [ca_itrm_group]
GRANT UPDATE ON [dbo].[ca_agent] TO [ca_itrm_group]
GRANT SELECT ON [dbo].[ca_agent] TO [ca_itrm_group_ams]
GRANT SELECT ON [dbo].[ca_agent] TO [dms_backup_group]
GRANT INSERT ON [dbo].[ca_agent] TO [dms_backup_group]
GRANT DELETE ON [dbo].[ca_agent] TO [dms_backup_group]
GRANT UPDATE ON [dbo].[ca_agent] TO [dms_backup_group]
GRANT SELECT ON [dbo].[ca_agent] TO [regadmin]
GRANT SELECT ON [dbo].[ca_agent] TO [swcmadmin]
GRANT INSERT ON [dbo].[ca_agent] TO [swcmadmin]
GRANT DELETE ON [dbo].[ca_agent] TO [swcmadmin]
GRANT UPDATE ON [dbo].[ca_agent] TO [swcmadmin]
GRANT SELECT ON [dbo].[ca_agent] TO [uapmadmin]
GRANT INSERT ON [dbo].[ca_agent] TO [uapmadmin]
GRANT DELETE ON [dbo].[ca_agent] TO [uapmadmin]
GRANT UPDATE ON [dbo].[ca_agent] TO [uapmadmin]
GRANT SELECT ON [dbo].[ca_agent] TO [uapmadmin_group]
GRANT INSERT ON [dbo].[ca_agent] TO [uapmadmin_group]
GRANT DELETE ON [dbo].[ca_agent] TO [uapmadmin_group]
GRANT UPDATE ON [dbo].[ca_agent] TO [uapmadmin_group]
GRANT SELECT ON [dbo].[ca_agent] TO [uapmbatch]
GRANT INSERT ON [dbo].[ca_agent] TO [uapmbatch]
GRANT DELETE ON [dbo].[ca_agent] TO [uapmbatch]
GRANT UPDATE ON [dbo].[ca_agent] TO [uapmbatch]
GRANT SELECT ON [dbo].[ca_agent] TO [uapmbatch_group]
GRANT INSERT ON [dbo].[ca_agent] TO [uapmbatch_group]
GRANT DELETE ON [dbo].[ca_agent] TO [uapmbatch_group]
GRANT UPDATE ON [dbo].[ca_agent] TO [uapmbatch_group]
GRANT SELECT ON [dbo].[ca_agent] TO [uapmreporting]
GRANT SELECT ON [dbo].[ca_agent] TO [uapmreporting_group]
GRANT SELECT ON [dbo].[ca_agent] TO [upmuser_group]
GO