Why does the DDL expression truncate?

The table structure remains the same after the truncate statement, and only records are deleted (with automatic commit). Then what is the reason why truncate is a DDL expression?

+6
source share
3 answers

I would add a few explanations here: By default, when truncating a table, you are not just deleting rows, you are implicitly telling Oracle Database to also perform the following tasks:

Cancels all space used by deleted rows, except as specified by the MINEXTENTS storage option

Sets the NEXT storage parameter to the size of the last power removed from the segment by the truncation process

Thus, it changes the definition of the repository and changes the structure of the table by resetting the watermark.

And it can't be DML, right? If the offer cannot be specified or is supplied with the DDL expression. If truncate is a DML statement, then Oracle would allow us to use truncation along with the where clause.
Note. The WHERE clause in SQL indicates that the SQL Data Manipulation Language (DML) statement should only affect rows that match the specified criteria.

+6
source

TRUNCATE resets the high water mark in the table, effectively eliminating all previously existing rows. Viewing it as a DDL statement allows it to be super-fast, as it allows it to function without saving the undo (rollback) of information, such as DML instructions.

+7
source

A simple practical explanation might be:

Truncate reinitializes the identifier, making changes to the data definition, therefore it is DDL , while Delete only removes records from the table and does not make any changes to its definition, why it is equal to DML .

How to create a table of names and insert some initial entries.

Created table Entered some records

Delete all records (Without where Clause) and reinsert the records. Authentication is not reinitialized.

Delete all records and insert again

Now truncate the table and insert records.

Crop a table and insert records

+4
source

Source: https://habr.com/ru/post/975883/


All Articles