Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / December 2007

Tip: Looking for answers? Try searching our database.

Alter statement for Identity Column

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
UDBDBA - 05 Dec 2007 22:22 GMT
Hi All,

I am seeing this behavior with IDENTITY COLUMN alter statements.

CREATE TABLE "SAMPLE   "."ID"  (
                 "KEYCOL" BIGINT NOT NULL GENERATED BY DEFAULT AS
IDENTITY (
                   START WITH +1
                   INCREMENT BY +1
                   MINVALUE +999
                   MAXVALUE +9223372036854775807
                   NO CYCLE
                   CACHE 100000
                   NO ORDER ) ,
                 "DWCONTRACTID" BIGINT NOT NULL )
                IN "STAGE_32K" ;

INSERT INTO SAMPLE.ID (KEYCOL) VALUES (1001);
DB20000I  The SQL command completed successfully.

SELECT * FROM SAMPLE.ID;

KEYCOL               DWCONTRACTID
-------------------- --------------------
                  1                 1001

 1 record(s) selected.

db2 "alter table sample.id alter keycol restart with 100"
DB20000I  The SQL command completed successfully.

db2 "insert into sample.id (dwcontractid) values (1002)"
DB20000I  The SQL command completed successfully.

db2 "select * from sample.id order by 2"

KEYCOL               DWCONTRACTID
-------------------- --------------------
                  1                 1001
                100                1002

 2 record(s) selected.

db2 "alter table vijay.id alter keycol set cache 100000"
DB20000I  The SQL command completed successfully.

db2 "insert into vijay.id (dwcontractid) values (1003)"
DB20000I  The SQL command completed successfully.

db2 "select * from vijay.id order by 2"

KEYCOL               DWCONTRACTID
-------------------- --------------------
                  1                 1001
              100                 1002
        100100                 1003

 3 record(s) selected.

--- Everything works good so far ----

Below is the problem!

db2 "alter table sample.id alter keycol restart with 999"
DB20000I  The SQL command completed successfully.

db2 "alter table sample.id alter keycol set cache 100000"
DB20000I  The SQL command completed successfully.

db2 "insert into sample.id (dwcontractid) values (1004)"
DB20000I  The SQL command completed successfully.

db2 "select * from sample.id order by 2"

KEYCOL               DWCONTRACTID
-------------------- --------------------
                  1                 1001
              100                 1002
        100100                 1003
                  1                 1004

 4 record(s) selected.

If you see above, the KEYCOL IDENTITY value is reset to 1, I set the
RESTART value to 999 and followed that alter statement with CACHE set
to 1000000. Whenever the two alter statements are executed back to
back, the IDENTITY column value is reset to 1 irrespective of the
RESTART VALUE.

Is this by design?

Thank you for time & effort in advance.

Vijay
Serge Rielau - 06 Dec 2007 02:35 GMT
> If you see above, the KEYCOL IDENTITY value is reset to 1, I set the
> RESTART value to 999 and followed that alter statement with CACHE set
[quoted text clipped - 3 lines]
>
> Is this by design?
I don't think so, but your sample is Frankenstein's monster.
E.g. your first insert statement won't work and you use different
schemata throughout the repro. So it's hardly compelling evidence of a
problem.

Could you provide a true repro?

Cheers
Serge
Signature

Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

UDBDBA - 06 Dec 2007 15:37 GMT
Hi Serge,

It's table sample.ID all the way. I wanted to substitute my name
"vijay" with "sample" for schema name in the posting...

What you see in the initial posting is the true repro.

Thanks!

Vijay

> > If you see above, the KEYCOL IDENTITY value is reset to 1, I set the
> > RESTART value to 999 and followed that alter statement with CACHE set
[quoted text clipped - 17 lines]
> DB2 Solutions Development
> IBM Toronto Lab
UDBDBA - 06 Dec 2007 15:55 GMT
Hi Serge,

I have the script tested and here is the output, still the same
problem! I see the problem in V8 FP12 & V9 FP2.

DROP TABLE SAMPLE.ID
DB20000I  The SQL command completed successfully.

CREATE TABLE "SAMPLE   "."ID"  ( "KEYCOL" BIGINT NOT NULL GENERATED BY
DEFAULT AS IDENTITY ( START WITH +1 INCREMENT BY +1 MINVALUE +999
MAXVALUE +9223372036854775807 NO CYCLE CACHE 100000 NO ORDER ) ,
"DWCONTRACTID" BIGINT NOT NULL ) IN "STAGE_1_ALL"
DB20000I  The SQL command completed successfully.

delete from sample.id
SQL0100W  No row was found for FETCH, UPDATE or DELETE; or the result
of a
query is an empty table.  SQLSTATE=02000

insert into sample.id (dwcontractid) values (1001)
DB20000I  The SQL command completed successfully.

alter table sample.id alter keycol restart with 100
DB20000I  The SQL command completed successfully.

insert into sample.id (dwcontractid) values (1002)
DB20000I  The SQL command completed successfully.

select * from sample.id order by 2

KEYCOL               DWCONTRACTID
-------------------- --------------------
                  1                 1001
                100                 1002

 2 record(s) selected.

alter table sample.id alter keycol set cache 100000
DB20000I  The SQL command completed successfully.

insert into sample.id (dwcontractid) values (1003)
DB20000I  The SQL command completed successfully.

select * from sample.id order by 2

KEYCOL               DWCONTRACTID
-------------------- --------------------
                  1                 1001
                100                 1002
             100100                 1003

 3 record(s) selected.

alter table sample.id alter keycol restart with 999
DB20000I  The SQL command completed successfully.

alter table sample.id alter keycol set cache 100000
DB20000I  The SQL command completed successfully.

insert into sample.id (dwcontractid) values (1004)
DB20000I  The SQL command completed successfully.

select * from sample.id order by 2

KEYCOL               DWCONTRACTID
-------------------- --------------------
                  1                 1001
                100                 1002
             100100                 1003
                  1                 1004

 4 record(s) selected.

Thank you.

Vijay
Serge Rielau - 06 Dec 2007 16:36 GMT
Vijay,

OK, I agree that is not working properly. Can you open a PMR?
If support sends you around refer them to me.

Cheers
Serge

Signature

Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.