# Add row to table in SQL Database

**URL:** <https://forum.inductiveautomation.com/t/add-row-to-table-in-sql-database/10395>\
**Category:** Ignition\
**Created:** [August 25, 2015, 8:42pm UTC](https://forum.inductiveautomation.com/t/add-row-to-table-in-sql-database/10395 "2015-08-25T20:42:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [August 26, 2015, 8:28am UTC](https://forum.inductiveautomation.com/t/add-row-to-table-in-sql-database/10395/2 "2015-08-26T08:28:43Z")

</div>

Bind your ignition table ‘Data’ property to a database table using an SQL Query.  
Then you can add rows to the database table with the code below.  
The ‘system.db.refresh’ function will update your ignition table.

```auto
string = event.source.parent.getComponent('Group').getComponent('Text Field').text
string2 = event.source.parent.getComponent('Group').getComponent('Text Field 1').text
string3 = event.source.parent.getComponent('Group').getComponent('Text Field 3').text
string4 = event.source.parent.getComponent('Group').getComponent('Text Field 2').text
string5 = event.source.parent.getComponent('Group').getComponent('Text Area').text
number = event.source.parent.getComponent('Group').getComponent('Numeric Text Field').intValue
table = event.source.parent.getComponent('Table')

db = "MyDatabase"

# Create the insert query
insertQuery = """INSERT INTO [%s] ([string], [string2], [string3], [string4], [string5], [number]) 
				 VALUES ('%s', '%s', '%s', '%s', '%s', %d)""" % (tableName, string, string2, string3, string4, string5, number)

# Insert the record in the database table
system.db.runUpdateQuery(insertQuery,db)

# Refresh the table data
system.db.refresh(table, "data")

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/add-row-to-table-in-sql-database/10395)._
