sql - Before Update Trigger Issues -
sql - Before Update Trigger Issues -
i'm trying create trigger accomplishes following
examines value of field action_type in row having update requested
if row (prior update) has action_type that's null, want insert value/string "change".
if row (prior update) has action_type contains string 'add', want maintain value in-tact.
if row (prior update) has action_type contains string 'change', want maintain value in-tact.
create trigger tbl8_change on holiday_date_table before update begin if ((select action_type holiday_date_table inserted.hid = holiday_date_table.hid) == null) insert holiday_date_table (action_type) values ('changed') inserted.hid = holiday_date_table.hid; if ((select action_type holiday_date_table inserted.hid = holiday_date_table.hid) == 'changed') insert holiday_date_table (action_type) values ('changed') inserted.hid = holiday_date_table.hid; if ((select action_type holiday_date_table inserted.hid = holiday_date_table.hid) == 'add') insert holiday_date_table (action_type) values ('add') inserted.hid = holiday_date_table.hid; end
my syntax little off, help appreciated.
you can utilize after
trigger same effect;
create trigger trg_hdt on holiday_date_table after update begin update hdt set hdt.action_type='change' holiday_date_table hdt bring together inserted on hdt.id = i.id hdt.action_type null end;
an sqlfiddle test with.
basically bring together updated rows table itself, , alter appropriate value of matches.
sql sql-server-2012
Comments
Post a Comment