Skip to content Skip to sidebar Skip to footer

Mysql How Do You Truncate A Table In A Stored Procedure?

I have a stored procedure that writes results to a Result table. How do you truncate / erase a table from within a stored procedure? example call peformTest() truncate TestResult

Solution 1:

If you want to remove all data from the table, then your syntax is correct:

truncate testResultTable;

or

truncatetable testResultTable;

Depending on your specific needs, if you need to get rid of the table correctly and then re-create it, you can do:

droptable testResultTable;
createtable testResultTable asselect ... from ... where ...

Solution 2:

Not sure if there is any difference in SQL vs stored procedure in the way they execute. But usually the format for truncating is: Truncate Table tableName; here is the reference: http://dev.mysql.com/doc/refman/5.0/en/truncate-table.html

Solution 3:

In the stored procedure simple:

DELETE FROM table WHERE 1 = 1


Other example in PL/SQL:

PL/SQL SP Truncate


Or solution by @Churk.

Post a Comment for "Mysql How Do You Truncate A Table In A Stored Procedure?"