I have some tables that I build as a part of my report rollup. I don't need them afterwards at all. Someone mentioned to truncate them as it would be faster.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
Delete Statement delete table rows and return the number of rows is deleted from the table.in this statement, we use where clause to deleted data from the table
Truncate statement Deleted or removing all the rows from the table.
Drop statement deleted all records as well as the structure of the table
From: http://www.orafaq.com/faq/difference_between_truncate_delete_and_drop_commands
The answers here match up to the question, but I'm going to answer the question you didn't ask. "Should I use truncate or delete?" If you are removing all rows from a table, you'll typically want to truncate, since it's much much faster. Why is it much faster? At least in the case of Oracle, it resets the high water mark. This is basically a dereferencing of the data and allows the db to reuse it for something else.
Drop gets rid of the table completely, removing the definition as well. Truncate empties the table but does not get rid of the definition.
DROP and TRUNC do different things:
TRUNCATE TABLE
DROP TABLE
As far as speed is concerned the difference should be small. And anyway if you don't need the table structure at all, certainly use DROP.
Drop drop whole table and all its structure
truncate delete all rows from table it is different from delete that it also delete indexes of rows