# Successful Insert into SQL

**URL:** <https://forum.inductiveautomation.com/t/successful-insert-into-sql/12637>\
**Category:** Ignition\
**Created:** [February 2, 2017, 6:35pm UTC](https://forum.inductiveautomation.com/t/successful-insert-into-sql/12637 "2017-02-02T18:35:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [February 2, 2017, 6:35pm UTC](https://forum.inductiveautomation.com/t/successful-insert-into-sql/12637/1 "2017-02-02T18:35:33Z")

</div>

Hi guys,  
I use the runPrepUpdate to insert some data into a SQL DB using scripting but I want to be able to give the user some sort of confirmation to let them know their insert was successful, what would be the best approach? is using getKey = 1 a way to go or are there other options out there. Thanks a bunch!

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [February 2, 2017, 11:22pm UTC](https://forum.inductiveautomation.com/t/successful-insert-into-sql/12637/2 "2017-02-02T23:22:50Z")

</div>

getKey = 1 is good. It means that a row was successfully inserted so you get a primary key back.

Anyway, if for some reason data is not successfully inserted an exception should be thrown.

Best,

---

<div class="post-metadata">

**Author:** ![jd1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jd1/32/18928_2.png) [@jd1](https://forum.inductiveautomation.com/u/jd1)\
**Post date:** [September 8, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/successful-insert-into-sql/12637/3 "2020-09-08T19:14:12Z")

</div>

I realized this is an only thread, but I haven’t been able to find a newer one in this topic. How would you go about using the primary key you get back to drive a confirmation message?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 9, 2020, 11:27am UTC](https://forum.inductiveautomation.com/t/successful-insert-into-sql/12637/4 "2020-09-09T11:27:20Z")

</div>

From the manual

````auto
# This example inserts a new user and gives it the 'admin' role. Demonstrates the ability to retrieve a newly created key value.
  
# Get the username/password
name = event.source.parent.getComponent('Name').text
desc = event.source.parent.getComponent('Description').text
building = event.source.parent.getComponent('Building').selectedValue
  
# Insert the value
id = system.db.runPrepUpdate("INSERT INTO machines (machine_name, description) VALUES (?, ?)", [name, desc], getKey=1)```

#You could then use system.gui.messageBox to send the returned id to the user.
````
