Table with self-incrementing primary key and current time field

How to get a primary key field that increments itself and a time field that updates itself?


Look at LGID00 and LGDTTM fields.

Create a table:

CREATE TABLE LGCUS00F
(
LGID00 INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
LGDTTM TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
LGNAME CHAR(50),
LGSURN CHAR(50))
RCDFMT LGCUS


Now try to add a record:

INSERT INTO LGCUS00F (LGNAME, LGSURN)
VALUES (‘Aldo’, ‘Succi’)
Let’s see the result:
SELECT * FROM LGCUS00F

As you can see, LGID00=1 and LGDTTM=2018-04-01-10.01.49.781922
That’s it!


Verified by MonsterInsights