senior
senior

Reputation: 2276

How can I know if a column in a table is really changed

How can I know if a column in a table is really changed? for example, I have the table product with the following rows:

id  | prod_name  | prod_code  | is_used
_________________________________________
1   | prod1      | code1      | 1
2   | prod2      | code2      | 0
3   | prod3      | code3      | 0
4   | prod4      | code4      | 0
5   | prod5      | code5      | 0
6   | prod6      | code6      | 0

I execute the following query

update product set is_used = 1 where prod_name like 'prod%'

In this simple example, all the rows will have is_used = 1 How can I know that for the first row is_used isn't changed ?

Upvotes: 0

Views: 50

Answers (2)

Ian Nelson
Ian Nelson

Reputation: 58783

You could add a trigger that compares the previous value of the field to the updated value of the field, and then performs whatever action you want if the field is "really" changed.

Upvotes: 1

Adarsh Shah
Adarsh Shah

Reputation: 6775

You have maintain an updated Datetime column and update it with the current Datetime when you update that row/column or have an audit table to capture the history.

Upvotes: 1

Related Questions