# Return uniqueidentifier primary key on INSERT, UPDATE

**URL:** <https://forum.inductiveautomation.com/t/return-uniqueidentifier-primary-key-on-insert-update/23518>\
**Category:** Ignition\
**Tags:** database\
**Created:** [March 21, 2019, 6:56pm UTC](https://forum.inductiveautomation.com/t/return-uniqueidentifier-primary-key-on-insert-update/23518 "2019-03-21T18:56:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul.bouillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.bouillon/32/7980_2.png) [@paul.bouillon](https://forum.inductiveautomation.com/u/paul.bouillon)\
**Post date:** [March 21, 2019, 6:56pm UTC](https://forum.inductiveautomation.com/t/return-uniqueidentifier-primary-key-on-insert-update/23518/1 "2019-03-21T18:56:03Z")

</div>

Hello All,

I’m using uniqueidentifier/guid as my primary keys in my table – was expecting the PK to be returned using the system.db.runPrepUpdate() method – keep getting “0” returned… am I missing something here? Does the getKey flag only work for identity/integer columns?

```auto
db = "aux_data"
query = "INSERT INTO skip_delay_reports (start_range, end_range) VALUES (?,?)"
args = [event.source.parent.getComponent('Date Range').startDate,event.source.parent.getComponent('Date Range').endDate]
report_id = system.db.runPrepUpdate(query,args,db,getKey=1)
print("Report ID: %s" %report_id)

```

Every time, output is:

```auto
Report ID: 0

```

the id column is populated by default using the newsequentialid() function

Currently using MS SQL server 13.0.4001.0

I’ve looked into using OUTPUT statements per the link below – don’t seem to work with the system.db.runPrepUpdate method…

> <https://dba.stackexchange.com/questions/125516/return-the-uniqueidentifier-generated-by-a-default-on-insert>

Any ideas? Perhaps I have to create a trigger on the SQL server side?

Kind Regards,

-Paul

---

<div class="post-metadata">

**Author:** ![paul.bouillon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.bouillon/32/7980_2.png) [@paul.bouillon](https://forum.inductiveautomation.com/u/paul.bouillon)\
**Post date:** [March 21, 2019, 7:12pm UTC](https://forum.inductiveautomation.com/t/return-uniqueidentifier-primary-key-on-insert-update/23518/2 "2019-03-21T19:12:03Z")

</div>

not sure why it always takes posting in the forum before stumbling upon the solution minutes later…

I ended up using:

```auto
db = "aux_data"
query = "INSERT INTO skip_delay_reports (start_range, end_range) OUTPUT INSERTED.id VALUES(?,?)"
args = [event.source.parent.getComponent('Date Range').startDate,event.source.parent.getComponent('Date Range').endDate]
report_id = system.db.runScalarPrepQuery(query,args,db)
print("Report ID: %s" %report_id)

```

Proper ID returned:

```auto
Report ID: 8A9BA257-32F7-43A4-8108-9447567C875C

```
