# Return inserted key with stored procedure

**URL:** <https://forum.inductiveautomation.com/t/return-inserted-key-with-stored-procedure/88567>\
**Category:** Ignition\
**Tags:** database, scripting, ignition81\
**Created:** [April 9, 2024, 8:29am UTC](https://forum.inductiveautomation.com/t/return-inserted-key-with-stored-procedure/88567 "2024-04-09T08:29:34Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 11, 2024, 11:48am UTC](https://forum.inductiveautomation.com/t/return-inserted-key-with-stored-procedure/88567/7 "2024-04-11T11:48:26Z")

</div>

Ignition's `getKey()` infrastructure can only get 32-bit integer keys. Larger integers are truncated to their lower 32 bits, and other types yield NULL. An alternative for many databases is available here:

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934/89):
>
> Automation Professionals is pleased to announce a new release of the Integration Toolkit module. This release adds one new scripting function, [system.db.runPrepInsert()](https://www.automation-pros.com/toolkit/doc/utility.html#runprepinsert). It is very similar to IA's [system.db.runPrepUpdate()](https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepUpdate), intepreting the query, args, database, and tx arguments in the same fashion. The getKey argument is omitted as moot, as this function always retrieves generated keys. The skipAudit optional argument is unimplemented. For Ignition v8.1+: [v2.0.15.240431913](https://www.automation-pros.com/ignition/Integration%20Toolkit-2.0.15.240431913-v81.modl) Do note the docu…

But note that MS SQL Server always returns a double, which only has fifty-something bits to hold integers.

In your situation, I'd use a stored procedure, called via the stored procedure scripting methods, with a registered output parameter to deliver the SCOPE\_IDENTITY.

---

_[View the full topic](https://forum.inductiveautomation.com/t/return-inserted-key-with-stored-procedure/88567)._
