Trigger if updating

posted by | Leave a comment

See “The deleted and inserted logical tables” for information about the deleted and inserted logical tables that can be included in trigger definitions.tests whether the specified column is included in the set list of an update statement or is affected by an insert.

" end if update (price) or update (advance) if (select count (*) from inserted where (inserted.price * inserted.total_sales) create table Employee West ( empid int primary key, empname varchar(30), empdob datetime, region char(5) constraint region_chk check (region='West')) create table Employee East ( empid int primary key, empname varchar(30), empdob datetime, region char(5) constraint region_chk check (region='East’)) create view Employees as select * from Employee East union all select * from Employee West create trigger Employees Insert Trig on Employees instead of insert as begin insert into Employee East select * from inserted where region = "East" insert into Employee West select * from inserted where region = "West" end --will insert the data into the Employee East table insert into Employees values (10, 'Jane Doe', '11/11/1967', 'East') --will insert the data into the Employee West table insert into Employees values (11, 'John Smith', '01/12/1977', 'West') --will insert multiple rows into Employee East and --Employee West tables.This can only be specified for constraint triggers.An optional comma-separated list of arguments to be provided to the function when the trigger is executed. Simple names and numeric constants can be written here, too, but they will all be converted to strings.create view employee_v as select id, name, my_decrypt (salary) from employee_t CREATE TRIGGER Employee Insert ON employee_v INSTEAD OF INSERT AS BEGIN INSERT employee_t SELECT id, name, my_encrypt (salary) FROM inserted END CREATE TRIGGER employee Update ON employee_v INSTEAD OF UPDATE AS BEGIN DELETE FROM employee_t WHERE id IN (SELECT id FROM deleted) INSERT employee_t SELECT id, name, my_encrypt (salary) FROM inserted END CREATE TRIGGER employee Delete ON employee_v INSTEAD OF DELETE AS BEGIN DELETE FROM employee_t WHERE id IN (SELECT id FROM deleted) END You can use the set command inside a trigger.The set option you invoke remains in effect during the execution of the trigger, then reverts to its former setting.

Leave a Reply

saxophone dating