# TRUNCATE TABLE and Transactions

**URL:** <https://forum.cloverdx.com/t/truncate-table-and-transactions/1611>\
**Category:** CloverDX Platform\
**Created:** [April 7, 2015, 12:00am UTC](https://forum.cloverdx.com/t/truncate-table-and-transactions/1611 "2015-04-07T00:00:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dflkid](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dflkid](https://forum.cloverdx.com/u/dflkid)\
**Post date:** [April 7, 2015, 12:00am UTC](https://forum.cloverdx.com/t/truncate-table-and-transactions/1611/1 "2015-04-07T00:00:00Z")

</div>

I’m importing a file into a MySQL database and I’m performing a TRUNCATE TABLE command via DBExecute component first. My concern is that I’d like to roll that truncate table command back if the rest of the graph fails for some reason so I’m not left with an empty table. Is there any way to accomplish this with transactions?

Thanks,  
Andrew

---

<div class="post-metadata">

**Author:** ![slechtaj](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@slechtaj](https://forum.cloverdx.com/u/slechtaj)\
**Post date:** [April 9, 2015, 4:54pm UTC](https://forum.cloverdx.com/t/truncate-table-and-transactions/1611/2 "2015-04-09T16:54:56Z")

</div>

Hi Andrew,

In order to wrap statements in DBExecute with DBOutputTable DML statements into one transaction, you will need to do the following:

- Set _threadSafeConnection_ attribute to _false_ - in _Database connection_ dialog go to _Advanced_ tab and uncheck _ **Thread-safe connection** _ check-box. See our [documentation](http://doc.cloveretl.com/documentation/UserGuide/index.jsp?topic=/com.cloveretl.gui.docs/docs/database-connection-wizard.html) for more information on this.

- Make sure DBExecute is in a phase with lower number than the one which is used for DBOutputTable.

- Set DBExecute’s attribute _ **Transaction set** _ to _Never commit_.

- In DBOutputTable dialog set _ **Action on error** _ attribute to _Rollback_

I would also recommend you using DELETE instead of TRUNCATE since TRUNCATE causes implicit mapping, therefore you won’t be able to rollback the statement in case of DBOutputTable failure. For more information on implicit mapping refer to MySQL [documentation (5.7)](https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html).

Hope it helps.
