其实account表有三个触发器SWcswebatg(中软自带的)、insertHTVC(另行增加的)、updateHTVC(另行增加的)
SWcswebatg
ALTER TRIGGER [dbo].[SWcswebatg] ON [dbo].[account] FOR UPDATE AS
BEGIN
declare @acct_num char(9)
if update(sw_update_flg) or update(sw_update_tm) --or update(confirm_flg)
return
declare stuscursor cursor for select i.acct_num from inserted i
join deleted d on d.acct_num=i.acct_num
and (d.acct_stus<>i.acct_stus) where i.csweb_flg='3' and i.acct_stus in ('0','4')
open stuscursor
fetch next from stuscursor into @acct_num
while (@@FETCH_STATUS = 0)
begin
update account set confirm_flg = '2', sw_update_flg = '1', sw_update_tm = getdate() where csweb_flg = '3' and acct_num=@acct_num
fetch next from stuscursor into @acct_num
end
close stuscursor
deallocate stuscursor
declare acctcursor cursor for select i.acct_num from inserted i
join deleted d on d.acct_num=i.acct_num
and (d.acct_stus<>i.acct_stus or d.acct_nm<>i.acct_nm or d.arr_dt<>i.arr_dt or d.dpt_dt<>i.dpt_dt
or d.rm_typ<>i.rm_typ or d.rm_num<>i.rm_num or d.crtf_num<>i.crtf_num or d.confirm_flg<>i.confirm_flg
or d.chkin_dt<>i.chkin_dt or d.chko_dt<>i.chko_dt) where i.csweb_flg='3'
open acctcursor
fetch next from acctcursor into @acct_num
while (@@FETCH_STATUS = 0)
begin
update account set sw_update_flg = '1', sw_update_tm = getdate() where csweb_flg = '3' and acct_num=@acct_num
fetch next from acctcursor into @acct_num
end
close acctcursor
deallocate acctcursor
END
insertHTVC
ALTER TRIGGER [dbo].[insertHTVC] ON [dbo].[account]
FOR INSERT
AS
declare @SN as char(9)
declare @CustomerName as varchar(40)
declare @Sex as char(2)
declare @CertificateNo as varchar(40)
declare @TelphoneNo as varchar(40)
select @SN=acct_num,@CustomerName=acct_nm,@Sex=sex_cd,@CertificateNo=crtf_num,@TelphoneNo=phone From inserted
insert into HTVC (SN,CustomerName,Sex,CertificateNo,TelphoneNo) values(@SN,@CustomerName,@Sex,@CertificateNo,@TelphoneNo)
updateHTVC
ALTER TRIGGER [dbo].[updateHTVC] ON [dbo].[account]
FOR
UPDATE
AS
if Update(acct_stus)
Begin
Declare @SN as varchar(50)
Declare @State as char(1)
Select @State=acct_stus From inserted
Select @SN=acct_num From deleted
Update HTVC Set HTVC.state=@State
Where HTVC.SN=@SN
End