0

我有一个触发器,如下所示:

ALTER TRIGGER [dbo].[areftblSalesDoc] ON [dbo].[tblSalesDoc]
AFTER INSERT
AS
Begin Try
    INSERT INTO ArefSms
        (DSIDName, SalesID, CustName, CustCellPhone, Fish, qt, ProdName)
    SELECT
        td.DSName, i.SalesID, tc.CustName, tc.CustCellPhone, i.Fish, NULL, NULL
        FROM inserted i
        left join tblDistributionStationDesc td on i.DSID = td.DSID
        left join tblCustomerDesc tc on i.CustomerID = tc.CustID

End Try
Begin Catch

End catch

当触发器不能保存任何东西并且有错误tblsalesdoc时也不能保存。但我不想那样。

我能做些什么?

4

1 回答 1

0

如果您想在出错的情况下跳过触发代码,您可以尝试使用SAVE TRANSACTION语句

ALTER TRIGGER [dbo].[areftblSalesDoc] ON [dbo].[tblSalesDoc]
AFTER INSERT
AS

SAVE TRANSACTION BeforeInsertInTrigger;

Begin Try
    INSERT INTO ArefSms
        (DSIDName, SalesID, CustName, CustCellPhone, Fish, qt, ProdName)
    SELECT
        td.DSName, i.SalesID, tc.CustName, tc.CustCellPhone, i.Fish, NULL, NULL
        FROM inserted i
        left join tblDistributionStationDesc td on i.DSID = td.DSID
        left join tblCustomerDesc tc on i.CustomerID = tc.CustID

End Try
Begin Catch
   ROLLBACK TRANSACTION BeforeInsertInTrigger;
   RETURN
End catch
于 2013-07-16T05:58:34.287 回答