t sql create trigger

Solutions on MaxInterview for t sql create trigger by the best coders in the world

showing results for - "t sql create trigger"
Frida
19 Jul 2020
1CREATE TRIGGER production.trg_product_audit
2ON production.products
3AFTER INSERT, DELETE
4AS
5BEGIN
6    SET NOCOUNT ON;
7    INSERT INTO production.product_audits(
8        product_id, 
9        product_name,
10        brand_id,
11        category_id,
12        model_year,
13        list_price, 
14        updated_at, 
15        operation
16    )
17    SELECT
18        i.product_id,
19        product_name,
20        brand_id,
21        category_id,
22        model_year,
23        i.list_price,
24        GETDATE(),
25        'INS'
26    FROM
27        inserted i
28    UNION ALL
29    SELECT
30        d.product_id,
31        product_name,
32        brand_id,
33        category_id,
34        model_year,
35        d.list_price,
36        GETDATE(),
37        'DEL'
38    FROM
39        deleted d;
40END
41Code language: SQL (Structured Query Language) (sql)