How to efficiently remove all rows from a table in DB2

妖精的绣舞 提交于 2020-01-03 08:14:12

问题


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?

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 truncate in MySQL)?

After I have deleted the rows, I will repopulate the database with similar amount of new data.


回答1:


It seems that following command works in newer versions of DB2.

TRUNCATE TABLE someschema.sometable IMMEDIATE  



回答2:


To truncate a table in DB2, simply write:

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.



来源:https://stackoverflow.com/questions/3616507/how-to-efficiently-remove-all-rows-from-a-table-in-db2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!