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
DROP TABLE deletes the table.
TRUNCATE TABLE empties it, but leaves its structure for future data.
From http://msdn.microsoft.com/en-us/library/aa260621(SQL.80).aspx
DROP Table
DELETE Table
TRUNCATE Table
DELETE TableA instead of TRUNCATE TableA? A common misconception is that they do the same thing. Not so. In fact, there are many differences between the two.
DELETE is a logged operation on a per row basis. This means that the deletion of each row gets logged and physically deleted.
You can DELETE any row that will not violate a constraint, while leaving the foreign key or any other contraint in place.
TRUNCATE is also a logged operation, but in a different way. TRUNCATE logs the deallocation of the data pages in which the data exists. The deallocation of data pages means that your data rows still actually exist in the data pages, but the extents have been marked as empty for reuse. This is what makes TRUNCATE a faster operation to perform over DELETE.
You cannot TRUNCATE a table that has any foreign key constraints. You will have to remove the contraints, TRUNCATE the table, and reapply the contraints.
TRUNCATE will reset any identity columns to the default seed value.
In the SQL standard, DROP table removes the table and the table schema - TRUNCATE removes all rows.
truncate removes all the rows, but not the table itself, it is essentially equivalent to deleting with no where clause, but usually faster.