MySQL如何在存储过程中截断表? [英] MySQL how do you truncate a table in a stored procedure?
本文介绍了MySQL如何在存储过程中截断表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个将结果写入结果表的存储过程.如何从存储过程中截断/删除表?
I have a stored procedure that writes results to a Result table. How do you truncate / erase a table from within a stored procedure?
例子
call peformTest()
truncate TestResultTable;
//do stuff with new data to insert into TestResultTable
end
推荐答案
如果你想从表中删除所有数据,那么你的语法是正确的:
If you want to remove all data from the table, then your syntax is correct:
truncate testResultTable;
或
truncate table testResultTable;
根据您的具体需求,如果您需要正确地摆脱表格然后重新创建它,您可以这样做:
Depending on your specific needs, if you need to get rid of the table correctly and then re-create it, you can do:
drop table testResultTable;
create table testResultTable as select ... from ... where ...
这篇关于MySQL如何在存储过程中截断表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文