触发SQL插入和更新

时间:2015-01-02 06:51:05

标签: mysql sql sql-server triggers

我有两张表INVENTORYINPUT

create table INPUT(
PRODUCTID nvarchar(10),
QUANTUMINPUT int
)

create table INVENTORY(
PRODUCTID nvarchar(10),
QUANTUM int,
QUANTUMINPUT int,
LASTQUANTUM int
)

当插入列trigger,表QUANTUMINPUT转换时,如何在SQL上创建SQL INVENTORY

1 个答案:

答案 0 :(得分:1)

Create trigger tr_update_insert_input
On dbo.[input]
After insert, update 
As 
Begin 
 Set nocount on; 

 Update intry
  Set intry.quantumnput = inpt.quantuminput
 From inventory intry inner join inserted inpt
 On intry.productid = inpt.productid 

End