# Sending data from Tag to Database

**URL:** <https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533>\
**Category:** Ignition\
**Tags:** ignition80, scripting, database\
**Created:** [June 9, 2022, 5:19am UTC](https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533 "2022-06-09T05:19:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_S1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@John\_S1](https://forum.inductiveautomation.com/u/John_S1)\
**Post date:** [June 9, 2022, 5:19am UTC](https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533/1 "2022-06-09T05:19:53Z")

</div>

Hi guys, I have a memory tag which contains a dataset of 3 columns and 10 rows and the row will be updated by one or 2 daily. I need to sync this to a database table and this table has to be updated automatically daily.  
I’m using a script to store the data inside the memory tag.

---

<div class="post-metadata">

**Author:** ![Gaurav.Shitole](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/gaurav.shitole/32/72050_2.png) [@Gaurav.Shitole](https://forum.inductiveautomation.com/u/Gaurav.Shitole)\
**Post date:** [June 9, 2022, 5:31am UTC](https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533/2 "2022-06-09T05:31:35Z")

</div>

Write TagValue Change script on the same tag to push updated values in the DB

---

<div class="post-metadata">

**Author:** ![John\_S1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@John\_S1](https://forum.inductiveautomation.com/u/John_S1)\
**Post date:** [June 9, 2022, 6:14am UTC](https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533/3 "2022-06-09T06:14:49Z")

</div>

Thanks for the reply. can you please provide me with an example?  
First I need to load all those values to the DB from tag then it should have to be automatically updated.

---

<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:** [June 9, 2022, 12:50pm UTC](https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533/4 "2022-06-09T12:50:46Z")

</div>

> [@John\_S1](#):
>
> values to the DB from tag

That sounds like a backwards design. Store rows to the DB. Query to update the tag with the most recent data.

---

<div class="post-metadata">

**Author:** ![John\_S1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@John\_S1](https://forum.inductiveautomation.com/u/John_S1)\
**Post date:** [June 10, 2022, 3:36am UTC](https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533/5 "2022-06-10T03:36:41Z")

</div>

Thanks for the suggestion, I will take a look at it. My requirement is like I’m taking several data from the Gateway for eg: Project names, I thought of storing that to a memory tag so that it will much faster and I send that data to DB and from there I’m going to use that in my client. like a backup…Path is like gateway data-- memorytag-- DB-- taking to the client.

I’m beginner, please suggest me standardized way for this…

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [June 10, 2022, 4:30am UTC](https://forum.inductiveautomation.com/t/sending-data-from-tag-to-database/60533/6 "2022-06-10T04:30:49Z")

</div>

DB transactions are not tied to clients or frontend sessions. The gateway is in charge to talk with the database, keep that in mind.  
Storing in a memory tag sounds ok if your database connection is faulty. Otherwise just keep data only in database.

If using a tag, I would a use transaction group for this with a 2 times daily trigger, but maybe is just a little overkilled.

I would avoid using tag change scripts, instead use scheduled script 2 times daily. Since 10 rows and 3 cols is a small set you should do it in a single query, first truncate and then insert updated data.
