Generated column doesn't work for z/os while it is ok in LUW

166 Views Asked by At

The following DDL is valid for LUW.

CREATE TABLE three_a(
    c1   INTEGER NOT NULL,
    c2   INTEGER NOT NULL GENERATED ALWAYS AS c1 + 10
)

But it is NOT valid for z/OS:

Any idea how to implement GENERATED ALWAYS to use it like computed columns in SQL Server?

3

There are 3 best solutions below

0
On BEST ANSWER

It is not implemented in the Z/OS version. You can find the allowable various options for "default" in the SQL manual under the "create table" SQL statement. There is an option to define a fieldproc on a column but it will not be (and do) what you want (more on it in the administration guide).

3
On

CREATE TABLE Table1 ( c1 INT NOT NULL, TS INT NOT NULL GENERATED ALWAYS AS IDENTITY );

ROWID type (instead of INT) is defined without the "AS IDENTITY"

1
On

Use a trigger for that. Look at SQL manual for the "create trigger" command. If you need it only while inserting rows then "before insert trigger" would suffice. If you want it for changes as well then you'll need an "update trigger" also.