Reputation: 4780
For the example table below, is there a way to configure the table to auto update the PreviousValue column with the data in the Value column when UPDATE occurs?
table Settings
(
Setting varchar(255),
Value varchar(255),
PreviousValue varchar(255)
)
Upvotes: 1
Views: 84
Reputation: 160833
Without trigger, you could also achieve this with below:
UPDATE Settings SET PreviousValue = Value, Value = :new_value WHERE Setting = :setting
Upvotes: 2
Reputation: 125855
CREATE TRIGGER my_trigger BEFORE UPDATE ON my_table FOR EACH ROW
SET NEW.PreviousValue = OLD.Value;
Upvotes: 4