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

Insert order is missing in the table


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

New User


Joined: 07 Sep 2011
Posts: 8
Location: india

PostPosted: Tue Dec 04, 2012 3:44 pm
Reply with quote

Hi

Using a Cobol program I am inserting records into a DB2 table. The records in the input file are in sorted order(on key). the primary key of the table is the combination of five columns, and it has the clustering index on these columns. After inserting the records i found that the table rows are not sorted based on the key(checked with PRINCETON tool). I traced the program using XPEDITOR, its inseting in the correct order.
What would be the reason, please help. Thanks.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Tue Dec 04, 2012 3:55 pm
Reply with quote

The reason is that DB2 does not guarantee retrieval of the rows in any particular order unless a ORDER BY clause is specified in the query.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Tue Dec 04, 2012 3:57 pm
Reply with quote

Is this the first time insert happening to the table??
Back to top
View user's profile Send private message
Lingam D

New User


Joined: 07 Sep 2011
Posts: 8
Location: india

PostPosted: Tue Dec 04, 2012 4:22 pm
Reply with quote

Yes. this is the first time insert is happening to the table.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Tue Dec 04, 2012 6:37 pm
Reply with quote

DB2 does not guarantee that rows will be inserted in the "proper" sequence. It may work out that way sometimes, but that is just a coincidence. You cannot rely on this behaviour.

As Akatsukami said, the only time that DB2 guarantees the order is when the rows are retrieved via a query that uses ORDER BY.
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: Tue Dec 04, 2012 9:30 pm
Reply with quote

Hello,

As others have mentioned, the only to be sure of the sequence the rows are returned is to use an ORDER BY.

If you run the same query with no order by over a few weeks, the sequence of the data returned may change from run to run.
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 Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Rotate partition-logical & physic... DB2 0
Search our Forums:

Back to Top