Deleting data by using TRUNCATE statements

You can use the TRUNCATE statement to delete all rows for base tables or declared global temporary tables.

You can embed a TRUNCATE statement in an application program or issue it interactively. TRUNCATE statements are executable statements that you can prepare dynamically. To truncate a table, you must have the proper authorization or be the owner of the table. The TRUNCATE statement must not be confused with the TRUNCATE function.

Example TRUNCATE statements

Begin general-use programming interface information.
  • Empty an unused inventory table regardless of any existing triggers and return its allocated space.
       TRUNCATE TABLE INVENTORY
    			DROP STORAGE
           IGNORE DELETE TRIGGERS;
  • Empty an unused inventory table regardless of any existing delete triggers but preserve its allocated space for later reuse.
       TRUNCATE TABLE INVENTORY
          REUSE STORAGE
          IGNORE DELETE TRIGGERS;
  • Empty an unused inventory table permanently (a ROLLBACK statement cannot undo the truncate operation when the IMMEDIATE option is specified) regardless of any existing delete triggers and preserve its allocated space for immediate use.
       TRUNCATE TABLE INVENTORY
           REUSE STORAGE
           IGNORE DELETE TRIGGERS
           IMMEDIATE;
End general-use programming interface information.