IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Problem with DB2 Sequences object


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
a027412

New User


Joined: 05 Jul 2007
Posts: 40
Location: Minneapolis, MN

PostPosted: Wed Jul 11, 2007 4:04 pm
Reply with quote

I face a problem with DB2 Sequences object.
I have created SEQUENCE as follows
Code:
(SEQ_I                             DECIMAL(15 , 0)
 GENERATED ALWAYS AS IDENTITY                     
   (START WITH                                 1 ,
    RESTART WITH                               1 ,
    INCREMENT BY                               1 ,
    CACHE                                     20 ,
    NO CYCLE                                     ,
    MINVALUE                                   1 ,
    MAXVALUE                     999999999999999 ,
    ORDER                                        )

For the first time i loaded the table with 1000 rows. Then i emptied the table and again loaded 1000 rows. Now the SEQ_I which has to start from 1, it started from 1001.
My requirement is:
1: When i continue loading record without emptying the table, the SEQ_I must be a continous one.
2: When i empty the table, the SEQ_I i should start with 1.

Please help me on this.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jul 13, 2007 5:32 am
Reply with quote

Hello,

How did you empty the table?
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Jul 13, 2007 7:40 am
Reply with quote

Have you read the manual? Emptying the table does not reset an auto generated sequence number. You need to either drop and recreate the table or reset the sequence number (I don't know if this can be done by a non-dba)
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Jul 13, 2007 7:42 am
Reply with quote

Also, if you are using an auto generated value as your primary key in the table, that is generally seen as bad practice.

We had to re-design a 400 million row table because some one had decided auto number primary keys were the way to go and even with indexing on the "natural" primary key, the table was completely unusable even for simple queries.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts z/vm installation problem All Other Mainframe Topics 0
No new posts Job scheduling problem. JCL & VSAM 9
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
No new posts Need to add field to copybook, proble... COBOL Programming 14
Search our Forums:

Back to Top