Sunday, May 12, 2019

One Trigger for Two Event In Table of SQL Server




Berikut ini Contoh Trigger di SQL Server untuk menjalankan Dua Event sekaligus yaitu :
Event ketika Insert, dan Delete :

        

CREATE TRIGGER production.trg_product_audit
ON production.products
FOR INSERT, DELETE
AS
BEGIN
    SET NOCOUNT ON;
    INSERT INTO production.product_audits(
        product_id, 
        product_name,
        brand_id,
        category_id,
        model_year,
        list_price, 
        updated_at, 
        operation
    )
    SELECT
        i.product_id,
        product_name,
        brand_id,
        category_id,
        model_year,
        i.list_price,
        GETDATE(),
        'INS'
    FROM
        inserted i
    UNION ALL
    SELECT
        d.product_id,
        product_name,
        brand_id,
        category_id,
        model_year,
        d.list_price,
        GETDATE(),
        'DEL'
    FROM
        deleted d;
END
 

Artikel Terkait

1 comments so far

SMD Technology's "Micro Touch Titanium trim" - iTanium-arts.com
The micro-touch titanium trim black titanium fallout 76 features a high performance engine, the lowest-priced ford titanium ecosport component, and a omega seamaster titanium smaller power titanium welder supply with a titanium granite low-priced component.


EmoticonEmoticon