SQLTeam.com | Weblogs | Forums

One roll trigger

trigger
sql2014

#1

Hey guys! I really need some help with this. I have two tables: TB_Funcionario and TB_Despesa. TB_Despesa have this FK, Cpf_cli and at the same time, it is the PK of TB_Funcionario. My trigger need to every time it happens a new value at TB_Funcionario the trigger insert Cpf_cli at TB_Despesa. And I have no ideia how to even begin. Help!


#2

This is how it can be done.
But,you need to modify the code as per your table definition.

CREATE TRIGGER trigger_UpdateItemDetails ON tbl_PurchaseDetails
FOR INSERT AS
BEGIN

INSERT INTO 
tbl_ItemDetails
(
    PurchaseID,
    Quantity,
    WarehouseID
)
SELECT 
    PurchaseID, 
    ItemQuantity, 
    WarehouseID
FROM 
    INSERTED

END