I am maintaining an audit table, where in I have a parent table and it s child table.I want to insert the primary key of the parent audit table into it s child audit table.
Should I be declaring a "before insert" instead of a "for insert" trigger. Here s my code:
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
上述代码不起作用,将表格放入交易中。