# SQL PK Duplicate Entry with AFTER\_INSERT trigger

**URL:** <https://forum.inductiveautomation.com/t/sql-pk-duplicate-entry-with-after-insert-trigger/101869>\
**Category:** Ignition\
**Tags:** database, scripting, ignition81\
**Created:** [February 4, 2025, 8:41pm UTC](https://forum.inductiveautomation.com/t/sql-pk-duplicate-entry-with-after-insert-trigger/101869 "2025-02-04T20:41:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Panko](https://avatars.discourse-cdn.com/v4/letter/p/c5a1d2/32.png) [@Panko](https://forum.inductiveautomation.com/u/Panko)\
**Post date:** [February 4, 2025, 8:41pm UTC](https://forum.inductiveautomation.com/t/sql-pk-duplicate-entry-with-after-insert-trigger/101869/1 "2025-02-04T20:41:37Z")

</div>

I have an issue where whenever I add an AFTER INSERT trigger to a specific table in a mySQL database, the transaction that trips the trigger will fail due to "Duplicate entry '0' for key 'assetevent.PRIMARY'".

If I remove the trigger, it works just fine.

The trigger in question updates the table, but does not cause another INSERT to occur.

```python
UPDATE `schemaA`.`assetevent` 
	SET `EndDate` = RecentStart 
    WHERE `indexEvent` = RecentEnd;

```

The trigger is used to update the previous entry's end date with the start date of the current entry being written.

The primary key of the table is indexEvent, and is set up as PK, NN, UQ, and AI. Any idea why I would be getting this error?
