1

我是触发器的新手,我有两个名为 ArefSms 和 tblSalesProd 的表

我想在插入我的触发器更新 ArefSms 后,tblSalesProd.SalesID=ArefSms.SalesID 为此建议我写下面的代码

USE [ACEDB]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER TRIGGER [dbo].[areftblSalesProd] ON [dbo].[tblSalesProd]
AFTER INSERT
AS
Begin Try
Update ArefSms 
       set
        qt=inserted.ProdQty
        where ArefSms.SalesID=inserted.SalesID



End Try
Begin Catch

End catch

但现在我有错误

Msg 4104, Level 16, State 1, Procedure areftblSalesProd, Line 9
The multi-part identifier "inserted.SalesID" could not be bound.

我能做些什么?

4

2 回答 2

3

您需要insertedupdate声明中指定。这是一个表格参考:

Update ArefSms 
    set qt=inserted.ProdQty
    from inserted
    where ArefSms.SalesID=inserted.SalesID;
于 2013-07-14T00:22:24.720 回答
1

从其他表更新表时(在本例中inserted),我更喜欢使用以下语法JOINs

UPDATE Aref
SET Aref.qt=inserted.ProdQty
FROM ArefSms Aref
   INNER JOIN inserted ON Aref.SalesID=inserted.SalesID
于 2013-07-14T00:28:02.317 回答