我有一个After Insert
触发器,它应该首先插入,然后插入另一个表。但是当在另一个表中插入数据时发生任何错误时,所有事务都会终止。我想在基表中插入第一个数据,无论触发器是否成功触发。
这是我的代码:
CREATE TRIGGER [dbo].[Insert_Teacher_Active_LC]
ON [dbo].[Teacher_Profile]
AFTER INSERT,UPDATE
AS
BEGIN
MERGE [ROSC].[dbo].[Active_LC] as d
USING (SELECT
DistrictID, upazilaID, LCID, LCVisitYr, Trimister,
CASE WHEN (TcrPres = 1 AND TcrMtchLCProf = 1)
THEN 1 ELSE 0
END AS TcrRpls
FROM INSERTED) AS s ON s.DistrictID = d.DistrictID
AND s.upazilaID = d.upazilaID
AND s.LCID = d.LCID
AND s.LCVisitYr = d.EduYr
WHEN MATCHED THEN
UPDATE
SET Trimister = s.Trimister, Tcr_Replace = s.TcrRpls
WHEN NOT MATCHED THEN
INSERT(DistrictID, UpazilaID, LCID, EduYr, Trimister, Tcr_Replace)
VALUES(DistrictID, UpazilaID, LCID, LCVisitYr, Trimister, TcrRpls);
-- Insert statements for trigger here
END