User:Gelbard/Sandbox
From Wikipedia, the free encyclopedia
In SQL, the TRUNCATE statement removes all the data from a table. The TRUNCATE statement is not actually a part of the SQL standard, but many relational database management systems implement it.
Contents |
[edit] Usage
The basic truncate statment has this syntax:
TRUNCATETABLEtable_name
The syntax may differ between databases. For example, in Oracle Database the syntax is as mentioned above, but in DB2 the statement lacks the word TABLE.
[edit] Difference between TRUNCATE and DELETE
Unlike the DELETE statement, which is a DML type statement, the TRUNCATE statement is a DDL type statement, and therefore it differs from the seemingly same statement: DELETE FROM table_name.
The differences are as follows:
[edit] DB2
- The
TRUNCATEstatement can ignore Delete triggers. - The
TRUNCATEstatement can perform immediateCOMMIT. - The
TRUNCATEstatement can keep the storage allocated to the table.
[edit] Oracle
- Oracle database automatically performs a
COMMITbefore and after theTRUNCATEstatement. - The
TRUNCATEstatement can drop all the storage allocated to the table. - The
TRUNCATEstatement can reset the high-water mark for the table. - The
TRUNCATEstatement ignores triggers. - A
TRUNCATEstatement can not be issued on a table which is a part of a cluster. - A
TRUNCATEstatement can not be issued on the parent table of an enabled foreign key constraint.
[edit] See also
In SQL Truncate statement doesn't delete the content of a table which is to be truncated while it removes the address of the table from the list containing addresses to identify the table. That's why Truncate statement is 300 times faster than Delete statement of SQL because Delete statement removes the content of table one-by-one[specify].
Truncate Table [schema][.] <table_name>;
|
|||||||||||||||||||||||
[[Category:SQL statements]] {{compu-lang-stub}}

