View previous topic :: View next topic
|
Author |
Message |
venkatm99
New User
Joined: 01 Jun 2006 Posts: 23 Location: Sinagpore
|
|
|
|
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 |
|
|
anamikak
New User
Joined: 10 May 2006 Posts: 64 Location: Singapore
|
|
|
|
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 |
|
|
|