# Create table in mysql using button script

**URL:** <https://forum.inductiveautomation.com/t/create-table-in-mysql-using-button-script/9232>\
**Category:** General Discussion\
**Created:** [October 27, 2014, 6:03am UTC](https://forum.inductiveautomation.com/t/create-table-in-mysql-using-button-script/9232 "2014-10-27T06:03:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhananjay\_vichare](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dhananjay_vichare/32/74712_2.png) [@dhananjay\_vichare](https://forum.inductiveautomation.com/u/dhananjay_vichare)\
**Post date:** [October 27, 2014, 6:03am UTC](https://forum.inductiveautomation.com/t/create-table-in-mysql-using-button-script/9232/1 "2014-10-27T06:03:46Z")

</div>

I want to create a table in MySQL database, using button script. Please let me know.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 27, 2014, 9:41am UTC](https://forum.inductiveautomation.com/t/create-table-in-mysql-using-button-script/9232/2 "2014-10-27T09:41:25Z")

</div>

Hi!

First, welcome to the forums.

Second, Short questions like this do not normally result in good answers. The more details you can provide, the better the answers become! ![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:") That being said, I’ll take the first stab at it…

Although such things are usually more easily handled in transaction groups, this will create a new, empty table:

[code]query=""“CREATE tableName(  
ndx INT NOT NULL AUTO\_INCREMENT  
t\_stamp DATETIME NOT NULL  
col1Name VARCAHR(20) NOT NULL  
col2Name INT  
col3Name FLOAT  
PRIMARY KEY (ndx)  
)”""

system.db.runUpdateQuery(query, datasource)[/code]

To be honest, doing something like this through a button script does not seem like a good workflow. Perhaps if you can tell us what you are trying to do, we can either explore this further, or suggest alternatives. 🙂

---

<div class="post-metadata">

**Author:** ![dhananjay\_vichare](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dhananjay_vichare/32/74712_2.png) [@dhananjay\_vichare](https://forum.inductiveautomation.com/u/dhananjay_vichare)\
**Post date:** [October 27, 2014, 1:51pm UTC](https://forum.inductiveautomation.com/t/create-table-in-mysql-using-button-script/9232/3 "2014-10-27T13:51:24Z")

</div>

Hi,  
Thank you for the suggestions.

I am trying to show the event log using audit log table. In the audit log table we have only tag path, for tag descriptions I had prepared one table. At the time of retrieving the events I am just pulling the descriptions for the tag from newly created table.

Now it is working fine, but I want to give this backup to our client. Hence I am trying to create table and insert the tags and there descriptions in the table using script, which will be easier to commission the system.

Thanks once again.
