Applying CURRENT TIMESTAMP On Updates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rickbray66
    New Member
    • Jun 2007
    • 7

    Applying CURRENT TIMESTAMP On Updates

    DB2 Express for Windows: DB2 v9.1.200.166


    Hello. I've recently started working with DB2. I'm in the process of migrating a DDL from MySQL over to DB2. Consider the following snipet:

    Code:
    CREATE TABLE `book_unit` (
      `book_unit_id` varchar(32) NOT NULL default '',
      `last_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
    The above statement in MySQL automatically sets the "last_updat ed" field to the current timestamp upon updates if the data is not supplied in the SQL statement. Is there an easy way to achieve this in DB2 without using a trigger? I've looked at "GENERATED BY DEFAULT" and "FOR EACH ROW ON UPDATE AS ROW CHANGE TIMESTAMP" documentation without much luck.

    Any help is greatly appreciated.

    Thanks!!


    Rick
  • rickbray66
    New Member
    • Jun 2007
    • 7

    #2
    Still haven't found an easy way to achieve this without using a trigger, so that looks like the route I'm headed.

    Just for reference:

    A new clause: FOR EACH ROW ON UPDATE ROW CHANGE TIMESTAMP

    has been implemented for DB2 9.1 for z/OS.

    This is exactly what I'm looking for, but unfortunately, it does not appear to work for DB2 Express 9.1 for Windows.


    Rick

    Comment

    Working...