我正在维护一个审计表,其中我有一个父表,它是子表。我想将父审计表的主键插入到它的子审计表中。
我是否应该声明“插入前”而不是“插入”触发器。这是我的代码:
CREATE trigger [trgAudtblChild] On [tblChild]
for Insert
as
BEGIN
declare @serNo bigint
declare @expSerNo int
declare @postPercent numeric (12, 2)
declare @prdSAPid varchar (50)
declare @lastUpdatedBy int
declare @lastUpdatedOn smalldatetime
SELECT
--@serno = serno,
@expSerNo = expSerNo ,
@postPercent = postPercent ,
@prdSAPid = prdSAPid ,
@lastUpdatedBy = lastUpdatedBy ,
@lastUpdatedOn = lastUpdatedOn
FROM INSERTED
select @serno = max(at_serno) from AT_tblParent
insert into AT_tblChild(serNo, expSerNo, postPercent
, prdSAPid, lastUpdatedBy, lastUpdatedOn
, change_column_index) values(
@serNo, @expSerNo, @postPercent
, @prdSAPid, @lastUpdatedBy, @lastUpdatedOn
, 'INSERTED')
End
Return
上面的代码不起作用并将表放入事务中。