11.1.5 Deleting all rows from a base table
If you want to delete all rows from a base table, we recommend that as a rule, you execute the TRUNCATE TABLE data manipulation SQL statement.
Executing the TRUNCATE TABLE statement allows you to delete all rows more quickly than using the DELETE statement (with the WHERE clause omitted). Moreover, since segments are released, you can reuse the area where the deleted row data was stored.
The following table shows the differences between the TRUNCATE TABLE and DELETE statements.
No. |
Compared item |
TRUNCATE TABLE statement |
DELETE statement (with the WHERE clause omitted) |
---|---|---|---|
1 |
Processing performance |
|
|
2 |
Releasing of segments |
|
|
3 |
Need to execute the COMMIT statement |
|
|
4 |
Locking (whether the statement can be concurrently executed on the same table with the SELECT statement) # |
|
|
5 |
Recommended execution timing |
|
|
- #
-
For details about the locked resources that are reserved when the TRUNCATE TABLE and DELETE statements are executed, and their lock modes, see 2.10.4 Locked resources that are reserved and their lock modes.
The following shows a specification example of deleting all rows from a base table.
- Specification example
-
All rows are deleted from the sales history table (SALESLIST).
TRUNCATE TABLE "SALESLIST"
For details about the specification format and rules for the TRUNCATE TABLE statement, see TRUNCATE TABLE (delete all rows in a base table) in Data Manipulation SQL in the manual HADB SQL Reference.
- Important
-
Before you delete all rows, check whether you need to re-execute the command for the base table for which the target rows are defined (whether the base table is non-updatable). For details about the check method, see (1) Checking whether a base table is non-updatable in 10.9.2 Checking the status and usage of a base table.
- If re-execution of the command is necessary
-
Re-execute the command. Then, delete all rows.
- If you deleted all rows when command re-execution was necessary (when the base table was non-updatable)
-
Temporary work files created by the interrupted command might remain. To delete the temporary work files, you must release all base tables from the non-updatable status.
For details about deleting temporary work files, see (2) When there are unneeded temporary work files on the disk in 15.2.5 Steps to take in the event of a shortage of disk space for storing temporary work files during command execution.