使用 VB.Net 从 MySQL 数据库中删除所有数据的查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23952249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Query for deleting ALL data from a database on MySQL using VB.Net
提问by user3678904
What's the query to delete alldata from a database? The reason for this is there are tons of data that will be processed and stored on that database and every month it should be cleaned in order to avoid having tons of data as the previous data will be irrelevant on the next cycle.
从数据库中删除所有数据的查询是什么?这样做的原因是有大量数据将被处理并存储在该数据库中,并且每个月都应该对其进行清理,以避免拥有大量数据,因为之前的数据将与下一个周期无关。
PS, is there such a query as:
PS,是否有这样的查询:
Dim sqlQuery As String = "DELETE ALL * FROM employee_table"
I've seen this questionbut I don't think it's the answer to what I'm looking to do.
我看过这个问题,但我认为这不是我想要做的事情的答案。
回答by T.J. Crowder
PS, is there such a query as:
Dim sqlQuery As String = "DELETE ALL * FROM employee_table"
PS,是否有这样的查询:
Dim sqlQuery As String = "DELETE ALL * FROM employee_table"
Yes:
是的:
Dim sqlQuery As String = "DELETE FROM employee_table"
That records the delete (in replication logs, etc.) like any other data modification. You might also see:
像任何其他数据修改一样记录删除(在复制日志等中)。您可能还会看到:
Dim sqlQuery As String = "TRUNCATE TABLE employee_table"
That does notrecord the delete (in replication logs, etc.).
这并没有记录删除(复制日志等)。
See the MySQL documentationfor the difference between an unqualified DELETE(a DELETEwith no WHERE) and a TRUNCATE, but basically: If you use replication, binlogs, etc. and need to have an accurate reflection of the actons that occurred, use DELETE; if you don't need that, you can use TRUNCATE, which operates more quickly (since it doesn't have to do the logging and such).
请参阅MySQL 文档了解 unqualified DELETE(a DELETEwith no WHERE) 和 a之间的区别TRUNCATE,但基本上:如果您使用复制、二进制日志等并且需要准确反映发生的动作,请使用DELETE; 如果您不需要它,您可以使用TRUNCATE, 它运行得更快(因为它不必进行日志记录等)。
Query for deleting ALL data from a database...
查询从数据库中删除所有数据...
The above is, of course, just for one table. To do multiple tables, just use multiple DELETEor TRUNCATEstatements.
当然,以上只是针对一张桌子。要做多个表,只需使用 multiple DELETEorTRUNCATE语句。
回答by Gusman
Yo can enumerate all the db tables and then delete its content.
您可以枚举所有数据库表,然后删除其内容。
To enumerate the tables you can do "SHOW TABLES;", and then iterate throug the results and truncate those tables "TRUNCATE TABLE (tablename);"
要枚举表,您可以执行“SHOW TABLES;”,然后遍历结果并截断这些表“TRUNCATE TABLE (tablename);”
Beware of relationships, if a row is referenced by a foreign key you will not be allowed to delete it, so you must delete the info hierarchically.
注意关系,如果一行被外键引用,你将不允许删除它,所以你必须分层删除信息。

