Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Violation of PRIMARY KEY constraint 'PK_PC_HISTORY_WORK'



As records are imported, a note record is made in a history table with a timestamp in the primary key. The primary key of the history record uses a timestamp for making the keys unique. If two records are added within the same millisecond, the keys will not be unique. This fails the primary key constraint which includes the time.

Error Messages

SQLState 23000, Error code 2627: Violation of PRIMARY KEY constraint 'PK_PC_HISTORY_WORK'. Cannot insert duplicate key in object 'dbo.PC_HISTORY_WORK'. 

Steps to Reproduce

1. Add a history record using getCurrentTimeStamp to provide the unique key.
2. Add another history record within the same millisecond also using getCurrentTimeStamp to provide the unique key.

Root Cause

The root cause of this problem is a defect in user code. Using the function getCurrentTimeStamp to provide keys to the history records is not robust. As this only provides uniqueness if no two records are created within the same millisecond, when two history records are created within the same millisecond, you get a PRIMARY KEY constraint violation


As a local-change, switch user code to use getCurrentTimeStampUnique which ensures
that unique keys are always created.

Published November 20, 2015 - Updated October 8, 2020

Was this useful?

0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us