Jump to content

SQL Truncate


DavidCrowe

Recommended Posts

It would be useful to have either a page on SQL TRUNCATE TABLE or a mention of it in the SQL DELETE tutorial. "DELETE from <table>" or "DELETE * FROM <table>" is recommended as a way to delete all data without deleting the table itself. Is this just a synonym for TRUNCATE? Is it guaranteed to do this as efficiently?

Link to comment
Share on other sites

They are different, truncate is much faster because it doesn't worry about updating indexes or things like that, it just resets the table and all of its indexes. It's similar to deleting a file, instead of actually going through and setting all of the data on disk to 0 or whatever, the OS just marks that area of the disk as unused. Truncate doesn't do the same as delete, it just says the table has no rows in 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...