sql violation of unique key constraint

12691
11
Jump to solution
10-03-2017 04:13 PM
AdelaideZumwalt1
Occasional Contributor II

When I run the following script, which has run successfully for me on a number of other tables I get the following error:

Violation of UNIQUE KEY constraint 'versions_uk'. Cannot insert duplicate key in object 'dbo.SDE_versions'. The duplicate key value is (Poles, DBO).

The primary key for the Poles table is the ObjectID.

 

EXEC dbo.create_version 'dbo.DEFAULT', 'Poles', 1, 1, 'This version contains data pushed from WMM to ESRI';
EXEC dbo.set_current_version 'Poles';
EXEC dbo.edit_version 'Poles', 1;
MERGE ElectricNetwork.dbo.POLE_evw
USING WMM_Export.dbo.Pole
ON ElectricNetwork.dbo.POLE_evw.esElementName = WMM_Export.dbo.Pole.wmElementName
WHEN MATCHED THEN
UPDATE SET ElectricNetwork.dbo.POLE_evw.GUID_WMM= WMM_Export.dbo.Pole.wm_ElementGuid;
EXEC dbo.edit_version 'Poles', 2;

0 Kudos
11 Replies
Asrujit_SenGupta
MVP Regular Contributor

You need to run the Diagnose and Repair tools to fix this:

Diagnose Version Tables—Help | ArcGIS Desktop 

Repair Version Tables—Help | ArcGIS Desktop 

Remember to backup before running the tools.

0 Kudos
AhmadSALEH1
Occasional Contributor III

Thanks Asrujit, 

Usually I do run those 2 tools, sometimes I get that there is multiversioned tables had orphaned and sometimes I get nothing orphaned. 

this issue keeps happening  all the day and its hard to keep disconnecting all users to apply diagnose and repair. I am looking for a method to prevent this from happening. any ideas? 

Thank you,

Ahmad 

0 Kudos