Audit Script Error

Document ID : KB000123184
Last Modified Date : 19/12/2018
Show Technical Document Details
Question:
I am running an audit script to archive records from the IT Asset Manager audit tables.
I am getting an error:
Error on line 295: The DELETE statement conflicted with the REFERENCE constraint "owned_resource_potr_fk1". The conflict occurred in database "MDB", table "dbo.al_aud_owned_resource_potr", column 'audit_trail_id'.
Answer:
After making a backup copy of the script, do the following:
Locate this line: 
delete from aud from al_aud_owned_resource_potr aud 
join #tmp_asset_audits temp on aud.own_resource_uuid=temp.own_resource_uuid 
and aud.audit_trail_id=temp.AUDIT_TRAIL_ID 
and aud.is_deleted = 1 

Remove the 'and aud.is_deleted = 1', so that the line reads: 

delete from aud from al_aud_owned_resource_potr aud 
join #tmp_asset_audits temp on aud.own_resource_uuid=temp.own_resource_uuid 
and aud.audit_trail_id=temp.AUDIT_TRAIL_ID 
and re-run the script.