If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > sequence table.-urgent please respond.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-07, 20:38
mary76 mary76 is offline
Registered User
 
Join Date: Jan 2007
Posts: 3
sequence table.-urgent please respond.

Hi All,
I created one sequence in DB2 udb. I want to know in which system tables, this information stores. your early information is appreciated.

Thanks in advance.

mary.
Reply With Quote
  #2 (permalink)  
Old 01-26-07, 23:06
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
SYSIBM.SYSSEQUENCES wil show you a list of sequences and contains the LASTASSIGNEDVAL. However this is really just highest value that has been cached, and not necessarily the highest value actually assigned. So unless teh sequence is defined as NO CACHE, it is not really the last assigned value. Also, the LASTASSIGNEDVAL may not be accurate in a DPF configuration (data partitioning feature) accross multiple nodes.

Note that all SYSIBM tables are undocumented in DB2 LUW and are subject to change at the whim of IBM. That is why only the SYSCAT views (such as SYSCAT.SEQUENCES) are documented (but the view does not have LASTASSIGNEDVAL).

To use the next value for a sequence for an insert statement:

CREATE SEQUENCE EMPSERIAL
AS INTEGER
START WITH 1
INCREMENT BY 1;

INSERT INTO EMPLOYEE ( SERIALNUMBER, FIRSTNAME, LASTNAME,
SALARY) VALUES(NEXTVAL FOR EMPSERIAL, 'John', 'Smith', 75000);


To get the last value for a sequence:
VALUES PREVVAL FOR <seq-name>

However, the PREVVAL command won't give you the correct answer unless you have already accessed (and thus incremented) the sequence in your current session using the NEXTVAL command.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 01-27-07, 17:25
mary76 mary76 is offline
Registered User
 
Join Date: Jan 2007
Posts: 3
Thumbs up Thanks!

Hi Marcus,
Thanks fo posting the reply.It was really helpful to me.Thank you so much.Great work.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On