Hello Vishal,

> 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
   as
   begin
     if (new.col3 is distinct from old.col3)
       then new.col5 = current_timestamp;
   end#
   set term ;#

If col3 is non-nullable you can simply use "new.col3 <> old.col3" in the 
test.

Mind you, an explicit update that re-enters the existing value in col3 
won't cause col5 to be updated!

HTH,

Paul Vinkenoog

  • [firebird-support... Vishal Tiwari vishuals...@yahoo.co.in [firebird-support]
    • [firebird-su... Vishal Tiwari vishuals...@yahoo.co.in [firebird-support]
      • Re: [fir... Paul Vinkenoog p...@vinkenoog.nl [firebird-support]
        • Re: ... Vishal Tiwari vishuals...@yahoo.co.in [firebird-support]
          • ... Vishal Tiwari vishuals...@yahoo.co.in [firebird-support]
            • ... Paul Vinkenoog p...@vinkenoog.nl [firebird-support]
              • ... Vishal Tiwari vishuals...@yahoo.co.in [firebird-support]
                • ... Paul Vinkenoog p...@vinkenoog.nl [firebird-support]

Reply via email to