Answers for "trigger sql server example"

SQL
7

sql trigger example

-- SQL Server (update my_table after update on my_table)
CREATE TRIGGER trigger_name ON my_table AFTER UPDATE AS
IF UPDATE (col_name)	-- Optional, for particular column
BEGIN
    UPDATE my_table SET my_col_date = getdate() FROM my_table 
END;
-- Oracle (insert into log table after update on my_table)
CREATE OR REPLACE TRIGGER trigger_name AFTER UPDATE ON my_table
FOR EACH ROW
BEGIN
    INSERT INTO my_log_table (LOG_DATE, ACTION) VALUES (SYSDATE, 'Changed');
END;
Posted by: Guest on May-15-2021
2

how use trigger in sql

CREATE TRIGGER Product_Details_tr 
BEFORE INSERT ON Product_Details 
FOR EACH ROW 
SET NEW.User_ID = CURRENT_USER();
Posted by: Guest on March-11-2021
0

Trigger Sql server

CREATE TRIGGER production.trg_product_audit
ON production.products
AFTER 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
Code language: SQL (Structured Query Language) (sql)
Posted by: Guest on May-31-2021
0

mssql trigger

-- SQL Server Syntax  
-- Trigger on an INSERT, UPDATE, or DELETE statement to a table or view (DML Trigger)  
  
CREATE [ OR ALTER ] TRIGGER [ schema_name . ]trigger_name   
ON { table | view }   
[ WITH <dml_trigger_option> [ ,...n ] ]  
{ FOR | AFTER | INSTEAD OF }   
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }   
[ WITH APPEND ]  
[ NOT FOR REPLICATION ]   
AS { sql_statement  [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }  
  
<dml_trigger_option> ::=  
    [ ENCRYPTION ]  
    [ EXECUTE AS Clause ]  
  
<method_specifier> ::=  
    assembly_name.class_name.method_name
Posted by: Guest on October-11-2020

Code answers related to "trigger sql server example"

Code answers related to "SQL"

Browse Popular Code Answers by Language