从表中删除所有数据的最佳方法是什么? [英] What's the best way to delete all data from a table?

查看:35
本文介绍了从表中删除所有数据的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 600 万行的 SQLite 表.

I have a SQLite table with 6 million rows.

执行 DELETE FROM TABLE 很慢;

Doing a DELETE FROM TABLE is quite slow;

删除表格然后重新创建它似乎更快.

Dropping the table and then re-creating it seems quicker.

我用它来导入数据库.

删除表是更好的方法还是有办法快速删除所有数据?

Would dropping the table be a better approach or is there a way to delete all data quickly?

推荐答案

一个很大的区别是 DELETE FROM TABLE 是 DML 而 DROP TABLE 是 DDL.这对于数据库事务非常重要.最后的结果可能是一样的,但这些操作却大不相同.

One big difference is that DELETE FROM TABLE is DML and DROP TABLE is DDL. This is very important when it comes to db transactions. The result at the end may be the same, but these operations are very different.

如果这只是您必须注意的性能,那么删除并重新创建表可能没问题.如果您需要在导入中进行事务,那么您必须注意 DDL 不包括在内,并且无法回滚.

If it's just performance you've to be aware of then it may be ok to drop and recreate the table. If you need transactions in your imports then you've to be aware that DDL is not covered and cannot be rollbacked for example.

这篇关于从表中删除所有数据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆