Hi,
using DB2 v9.5 fixpack 2a on Linux I have created a table with "generated always as identity" column.
Code:
CREATE TABLE ADMIN.TAB
(
ID INT NOT NULL GENERATED ALWAYS AS IDENTITY
(START WITH 1,
INCREMENT BY 1,
NO CACHE),
COL2 INT NOT NULL UNIQUE
);
Above table also has a unique value in col2, to easily demonstrate the problem.
Code:
INSERT INTO ADMIN.TAB (COL2) VALUES (1);
INSERT INTO ADMIN.TAB (COL2) VALUES (1);
INSERT INTO ADMIN.TAB (COL2) VALUES (2);
Second insert fails because of unique constraint.
Looking at the table with select:
Code:
SELECT * FROM ADMIN.TAB;
and I see in first ID column the following numbers: 1 and 3.
Code:
ID COL2
----------- -----------
1 1
3 2
I have expected to see 1 and 2 value, but 2 is missing and 3 is inserted. How to prevent missing values (like 2) in ID column?
Why does DB2 increases sequence number if SQL fails?
Thanks