how use trigger in sql
CREATE TRIGGER Product_Details_tr
BEFORE INSERT ON Product_Details
FOR EACH ROW
SET NEW.User_ID = CURRENT_USER();
how use trigger in sql
CREATE TRIGGER Product_Details_tr
BEFORE INSERT ON Product_Details
FOR EACH ROW
SET NEW.User_ID = CURRENT_USER();
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)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us