我有一个包含 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.
更多推荐
从表中删除所有数据的最佳方法是什么?
发布评论