> I have one table say "MyTable", which has five columns, say Col1,
> Col2,...,Col5 and it has 10 rows. Col5 is of Timestamp.
> My issue is, whenever I am updating Col3, that time, only for that row
> of Col5, Timestamp value should be updated to the current timestamp.
> What would be the best option for this?
> If trigger is the best way then how would I do it? As I never worked
> on Triggers.
Yes, a trigger is definitely the way to go, e.g. like this:
set term #;
create trigger before update on MyTable
if (new.col3 is distinct from old.col3)
then new.col5 = current_timestamp;
set term ;#
If col3 is non-nullable you can simply use "new.col3 <> old.col3" in the
Mind you, an explicit update that re-enters the existing value in col3
won't cause col5 to be updated!