Situation: At SQL Assistant, I need to create a table using an autonumber field as part of a composed primary key
Complication: When I set that autonumber field on UNIQUE PRIMARY INDEX statement, I get an error msg 5784 - “illegal use of identity field”.
What am I doing wrong? Where can I find more details about this kind of error msg?
Eg: CREATE TABLE LIB.TABLE ( Transaction_ID INTEGER TITLE 'Transaction ID' NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 999999999 NO CYCLE), Party_ID INTEGER TITLE 'Party ID' NOT NULL) UNIQUE PRIMARY INDEX ( Transaction_ID , Party_ID );
The intention is to have a table like if we have this on the table: Transaction_ID Party_ID 1 1 1 2 2 1
Identity columns cannot be used as part of a composite primary or secondary index. It doesn't make sense as part of a PI since the identity is inherently unique. Take a look at the create table (column definition clause) documentation, it's on page 1-318 in the V2R5.1 Data Definition Statements manual.