# Read and Write DB table

**URL:** <https://forum.inductiveautomation.com/t/read-and-write-db-table/11282>\
**Category:** Ignition\
**Created:** [February 29, 2016, 5:13am UTC](https://forum.inductiveautomation.com/t/read-and-write-db-table/11282 "2016-02-29T05:13:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jayden](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Jayden](https://forum.inductiveautomation.com/u/Jayden)\
**Post date:** [February 29, 2016, 5:13am UTC](https://forum.inductiveautomation.com/t/read-and-write-db-table/11282/1 "2016-02-29T05:13:08Z")

</div>

Hi everyone,

I’m new to ignition and scripting, so this is no doubt a simple question.

I would like to have some buttons in my project to write to and from cells in a DB table.

Button 1 - Writes value from DB cell to PLC tag.

Button 2 - Writes PLC tag value to DB cell.

Can anyone point me in the right direction on this?

Thanks

---

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [March 2, 2016, 7:42pm UTC](https://forum.inductiveautomation.com/t/read-and-write-db-table/11282/2 "2016-03-02T19:42:39Z")

</div>

These scripts on the actionPerformed event on the button should do it for you.

`value = system.db.runScalarQuery("SELECT value FROM table WHERE something = x")
system.tag.write("Folder\Tag",value)`

`value = system.tag.read("Folder\Tag").value
sql = "UPDATE table SET column = ? where something = x"
system.db.runPrepUpdate(sql, [value])`

---

<div class="post-metadata">

**Author:** ![Jayden](https://avatars.discourse-cdn.com/v4/letter/j/db5fbb/32.png) [@Jayden](https://forum.inductiveautomation.com/u/Jayden)\
**Post date:** [March 3, 2016, 9:28am UTC](https://forum.inductiveautomation.com/t/read-and-write-db-table/11282/3 "2016-03-03T09:28:06Z")

</div>

Thats great, Thanks!

Ill give this a try in the morning.
