MySQL 从表中删除所有

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3000917/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:15:00  来源:igfitidea点击:

delete all from table

sqlmysqlms-accessoptimizationperformance

提问by l--''''''---------''''''''''''

what's faster?

什么更快?

DELETE FROM table_name;

or

或者

DELETE FROM table_name where 1=1;

why?

为什么?

does truncate tablework in access?

truncate table在访问中工作吗?

回答by Jaymz

You can use the below query to remove all the rows from the table, also you should keep it in mind that it will reset the Identity too.

您可以使用以下查询从表中删除所有行,您还应该记住它也会重置身份。

TRUNCATE TABLE table_name

回答by Sarfraz

This should be faster:

这应该更快:

DELETE * FROM table_name;

because RDBMS don't have to look whereis what.

因为RDBMS 不用看where是什么。

You should be fine with truncatethough:

不过你应该没问题truncate

truncate table table_name

回答by Oladimeji Ajeniya

This is deletes the table table_name.

这是删除表table_name

Replace it with the name of the table, which shall be deleted.

替换为表名,表名将被删除。

DELETE FROM table_name;

回答by Pekka

There is a mySQL bug reportfrom 2004 that still seems to have some validity. It seems that in 4.x, this was fastest:

2004 年的 mySQL 错误报告似乎仍然具有一定的有效性。似乎在 4.x 中,这是最快的:

DROP table_name
CREATE TABLE table_name

TRUNCATE table_namewas DELETE FROMinternally back then, providing no performance gain.

TRUNCATE table_name当时是在DELETE FROM内部,没有提供性能提升。

This seems to have changed, but only in 5.0.3 and younger. From the bug report:

这似乎发生了变化,但仅限于 5.0.3 及更小版本。从错误报告:

[11 Jan 2005 16:10] Marko M?kel?

I've now implemented fast TRUNCATE TABLE, which will hopefully be included in MySQL 5.0.3.

[2005 年 1 月 11 日 16:10] Marko M?kel?

我现在已经实现了快速 TRUNCATE TABLE,它有望包含在 MySQL 5.0.3 中。

回答by Pekka

You can also use truncate.

您也可以使用截断。

truncate table table_name;