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

Timestamp as a part of primary key


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

New User


Joined: 01 Jun 2006
Posts: 23
Location: Sinagpore

PostPosted: Thu Jun 15, 2006 11:23 am
Reply with quote

hi

Is Timestamp being a part of primary key is good or not????

Every time i insert a record into the table coz of the timestamp,
there is no chance of voilation of primayy key.But ,wht is the other side of having timestamp as a part of primary key.


Cheers

venkat
Back to top
View user's profile Send private message
anamikak

New User


Joined: 10 May 2006
Posts: 64
Location: Singapore

PostPosted: Thu Jun 15, 2006 1:13 pm
Reply with quote

You could go in for timestamp as primary key when implementation of multiple column primary key is difficult or you do not have any other column as your choice for primary key.

To use timestamps for primary key values you create a column and assign it the TIMESTAMP data type with NOT NULL WITH DEFAULT. When inserting rows DB2 will automatically assign the column a value equal to the current timestamp at the time the row is inserted(in other words dont give a value for this column) . This works well excepting when you are inserting new values so rapidly that the two rows are inserted at the same exact time. Hence you provide retry logic in your application program in case duplicate key values are inserted. Check for SQLCODE ?803, and if received, retry the INSERT. It is possible to get duplicate key values when two transactions try to insert to the table at exactly the same time.
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 To get the count of rows for every 1 ... DB2 3
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Timestamp difference and its average ... DB2 11
Search our Forums:

Back to Top