【问题标题】:Update a table after insert data on another table using trigger使用触发器在另一个表上插入数据后更新表
【发布时间】:2015-03-21 20:29:42
【问题描述】:

当向 table_a 插入一行时,我必须更新 table_b 中的一列。

查询

CREATE TRIGGER trg_Update
ON table_a FOR INSERT
AS 
UPDATE table_b
SET Sold_Qty=inserted.qty
WHERE OrdNo=inserted.OrdNo;

我收到以下错误。

Msg 4104, Level 16, State 1, Procedure trg_Update, Line 6
The multi-part identifier "inserted.OrdNo" could not be bound.

【问题讨论】:

    标签: sql-server triggers


    【解决方案1】:

    试试这个代替UPDATE查询:

    UPDATE table_b
    SET Sold_Qty=inserted.qty
    FROM table_b b
    INNER JOIN inserted ON b.OrdNo=inserted.OrdNo;
    

    【讨论】:

    • @Ullas 不客气。我最初对 OP 的评论是由于我误读了 bound for found :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-01
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多