MySQL 删除mysql表中的所有记录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8091053/
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
delete all record from table in mysql
提问by Sami
I am trying to delete all records from a table. My query is:
我正在尝试从表中删除所有记录。我的查询是:
delete from tableName.
But it reports the following error:
但它报告以下错误:
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor -> Query Editor and reconnect."
错误代码:1175。您正在使用安全更新模式,并且您尝试更新没有使用 KEY 列的 WHERE 的表要禁用安全模式,请切换首选项 -> SQL 编辑器 -> 查询编辑器中的选项并重新连接。”
How do I resolve this?
我该如何解决?
回答by Thirler
truncate tableName
truncate tableName
That is what you are looking for.
这就是你要找的。
Truncate will deleteall records in the table, emptying it.
截断将删除表中的所有记录,清空它。
回答by Sandeep Pathak
It's because you tried to update a table without a WHERE that uses a KEY column.
这是因为您尝试更新没有使用 KEY 列的 WHERE 的表。
The quick fix is to add SET SQL_SAFE_UPDATES=0; before your query :
快速修复是添加 SET SQL_SAFE_UPDATES=0; 在您的查询之前:
SET SQL_SAFE_UPDATES=0;
Or
或者
close the safe update mode. Edit -> Preferences -> SQL Editor -> SQL Editor remove Forbid UPDATE and DELETE statements without a WHERE clause (safe updates) .
关闭安全更新模式。Edit -> Preferences -> SQL Editor -> SQL Editor 删除没有 WHERE 子句(安全更新)的 Forbid UPDATE 和 DELETE 语句。
BTW you can use TRUNCATE TABLE tablename;
to delete all the records .
顺便说一句,您可以使用 TRUNCATE TABLE tablename;
删除所有记录。