Re: Yet another query question... shorti wrote:
> I am inserting a record into a table that has an identity column that
> does a GENERATED ALWAYS. It is the only column in the table that
> gives the record its uniqueness. I want to capture this number when I
> insert a record. How can I do it in one step?
Here is a quick example showing SELECT FORM INSERT:
CREATE TABLE T(ID INT GENERATED ALWAYS AS IDENTITY,
C2 INT,
C3 INT GENERATED ALWAYS AS (c2 + 10),
c4 INT);
CREATE TRIGGER trg BEFORE INSERT ON T
REFERENCING NEW AS n FOR EACH ROW
SET c4 = c2 * 10;
SELECT id, c3, c4 FROM NEW TABLE(INSERT INTO T(c2) VALUES 5);
ID C3 C4
----------- ----------- -----------
1 15 50
1 record(s) selected.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab |