SQL 如何有效地从 DB2 中的表中删除所有行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3616507/
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
How to efficiently remove all rows from a table in DB2
提问by Juha Syrj?l?
I have a table that has something like half a million rows and I'd like to remove all rows.
我有一个大约有一百万行的表,我想删除所有行。
If I do simple delete from tbl
, the transaction log fills up. I don't care about transactions this case, I do not want to rollback in any case. I could delete rows in many transactions, but are there any better ways to this?
如果我做 simple delete from tbl
,事务日志就会填满。我不在乎这种情况下的事务,无论如何我都不想回滚。我可以删除许多事务中的行,但有没有更好的方法呢?
How to efficiently remove all rows from a table in DB2? Can I disable the transactions for this command somehow or is there special commands to do this (like truncatein MySQL)?
如何有效地从 DB2 中的表中删除所有行?我可以以某种方式禁用此命令的事务,还是有特殊的命令可以执行此操作(例如MySQL 中的truncate)?
After I have deleted the rows, I will repopulate the database with similar amount of new data.
删除行后,我将使用类似数量的新数据重新填充数据库。
回答by Juha Syrj?l?
回答by Luka Milani
To truncate a table in DB2, simply write:
要在 DB2 中截断表,只需编写:
alter table schema.table_name activate not logged initially with empty table
From what I was able to read, this will delete the table content without doing any kind of logging which will go much easier on your server's I/O.
从我能够阅读的内容来看,这将删除表内容而不进行任何类型的日志记录,这将在您的服务器的 I/O 上变得更加容易。