LUA example: Empty a table completely

In this example we’ll see how a simple script can empty a table, deleting all the data it contains.

WARNING! Once the script has run, the data cannot be recovered!

Script Group
Program
Event
Action

For this operation we’ll use a database command made specifically for deleting data from a table

database.deletedatarowsql("SELECT * FROM items")

The deletedatarowsql command deletes all the data returned by the SQL string. This command is normally used with additional filters, for example:

database.deletedatarowsql("SELECT * FROM items WHERE eli = 1")

This way only some records are deleted. Without any condition, the command deletes all the records. The string must always include the gguid field. It is used to uniquely identify the record to delete and, if the database is a cloud database, to delete it on the synchronization server too.

If the table is linked to a section, you can add the refresh command

program.refreshsection("items")