Jump to content

What is the difference/advandages/disadvantages


Skynet

Recommended Posts

DELETE FROM tablename WHERE ...... deletes individual rowsTRUNCATE tablename deletes all rows in the table. In some version of sql it also resets any auto increment back to zero. Its equivalent of DROPping the table (ie deleting it completely) and then recreating it. There are difference depending on version of sql/mysql and also some differences depending on the type of database (innodb, myisam).

Link to comment
Share on other sites

To add to that, as you add and remove rows to a table, you can imagine that the table has a "high-water mark", which would be the maximum size that the table has reached. Even as you delete rows, the high-water mark stays where it is, and that much space is still being used by the table. A delete will just delete the rows, and leave the high-water mark (and table size) where it is. A truncate will delete the row and then rebuild the table to set the high-water mark lower to the current size of the table. I believe only Oracle supports truncate, but I may be wrong. And like murfitUK said, it is equivalent to dropping the table and then adding all of the rows back to it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...