DB2 deleting data from a table

Source: Internet
Author: User
Tags db2 table definition

DB2 database system to build the table, there will inevitably be the data in the table to clear the demand, this article will introduce you to the DB2 database of four methods of data deletion, for your reference, you can choose according to the actual situation, hope to be helpful.

1. Use the DELETE statement, which is:

DELETE from < table name >

This statement clears all the data in the table, but because this operation will log, the execution will be slower, and it is important to note that if the table is large, you should consider whether there is enough log space to keep the delete operation successful.

2. Use the not logged initially option, i.e.:

ALTER table < table name > ACTIVATE not logged initially with EMPTY table

This method is only available if the table you are manipulating is defined when the not logged initially option is selected at the time of creation. The entire delete operation will not log, so execution speed is the fastest of several methods, but the deleted data is not recoverable.

3. Use the IMPORT or LOAD command, which is:

IMPORT From/dev/null of DEL REPLACE into < table name >-(Unix System)
or IMPORT from < empty file > of DEL REPLACE into < table name >

LOAD From/dev/null of DEL REPLACE into < table name > nonrecoverable-(Unix system)

or LOAD from < empty file > of DEL REPLACE into < table name > nonrecoverable

In this method, the REPLACE import method first empties all the data in the table, and then import/load imports the empty data into the table, enabling the cleanup of the data.

4. Use the Drop/create TABLE statement, which is:

DROP table < table name >
CREATE table < table name > < Field definition >

If you save a definition statement for a table, or if you have used the Db2look command to obtain a script for the table definition, you can delete the entire table and then recreate the table. If the table is large, the data can be emptied in this way faster than method one.

If you want to implement the effect of TRUNCATE TABLE, use the import from empty file method, other methods are not good.

DB2 deleting data from a table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.