# Update Query vs StoredProcedure vs system.db.runUpdateQuery

**URL:** <https://forum.inductiveautomation.com/t/update-query-vs-storedprocedure-vs-system-db-runupdatequery/65219>\
**Category:** Ignition\
**Created:** [October 14, 2022, 6:43am UTC](https://forum.inductiveautomation.com/t/update-query-vs-storedprocedure-vs-system-db-runupdatequery/65219 "2022-10-14T06:43:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dharani\_T](https://avatars.discourse-cdn.com/v4/letter/d/bc8723/32.png) [@Dharani\_T](https://forum.inductiveautomation.com/u/Dharani_T)\
**Post date:** [October 14, 2022, 6:43am UTC](https://forum.inductiveautomation.com/t/update-query-vs-storedprocedure-vs-system-db-runupdatequery/65219/1 "2022-10-14T06:43:30Z")

</div>

Hi,

I am currently inserting values into a table (say machine status) and this table will get updated once the status has been changed.  
I am using an update query with some sub queries to execute the above. I have a dilemma like whether this logic slows down the gateway (as longest query) or impacts the db.  
Query eg:

```auto
UPDATE tbl_productiondata AS pd
,
                 (SELECT RunID,EquipmentID
                    FROM cdcms.tbl_productiondata where EquipmentID= :iEquipmentID order by RunID desc limit 1, 1) As t
SET pd.Actual_OrderEndTime = :iOrderEndTime,
        pd.Actual_OrderRunTime = TIME_TO_SEC(TIMEDIFF(:iOrderEndTime, Actual_OrderStartTime)),
        pd._modifiedDate = NOW(),
        pd._modifiedUser = "ign_upd"
WHERE pd.RunID = t.RunID
AND pd.EquipmentID = t.EquipmentID
AND pd.Actual_OrderEndTime IS NULL

```

What below logic is recommended to do the mentioned function.  
Update Query or StoredProcedure or system.db.runUpdateQuery

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [October 14, 2022, 12:51pm UTC](https://forum.inductiveautomation.com/t/update-query-vs-storedprocedure-vs-system-db-runupdatequery/65219/2 "2022-10-14T12:51:17Z")

</div>

Well, no matter how you execute the query, it must be an Update query, so that “logic” doesn’t make since in this context.

You can choose to execute the query from a Named Query, a stored procedure, or one of the scripting functions. Really that comes down to personal preference.

Personally I would use a Named Query, as I like the advantages that they give over the other options.

As to where the impact is, that depends on a few things.

Running queries is a blocking task, which means that if you run one in a place that should be executing as quickly as possible (e.g. Vision GUI thread, Tag Value Change Scripts, etc…) you could very well see the impact of the overall latency. The actual processing impact will occur on the DB, in the unfortunate event that both your DB and Gateway are on the same server then the gateway could also feel that impact.

All of this relies heavily on how your system is set up, the flavor of DB you are using, and how many rows you’re operating on, not to mention any overhead from things like transfer rate.
