I have a table test_123
with the column as:
int_1 (int),
datetime_1 (datetime),
tinyint_1 (tinyint),
datetime_2 (datetime)
So when column datetime_1
is updated and the value at column tinyint_1
= 1 that time i have to update my column datetime_2
with column value of datetime_1
I have created the below trigger for this.. but with my trigger it is updating all datetime2
column values with datetime_1
column when tinyint_1
= 1 .. but i just want to update that particular row where datetime_1
value has updated( i mean changed)..
Below is the trigger..
CREATE TRIGGER test_trigger_upd
ON test_123
FOR UPDATE
AS
FOR EACH STATEMENT
IF UPDATE(datetime_1)
BEGIN
UPDATE test_123
SET test_123.datetime_2 = inserted.datetime_1
WHERE test_123.tinyint_1 = 1
END