Jump to content
DavidCrowe

SQL Truncate

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...