TRUNCATE TABLE Syntax

11 February 2012 By Praveen Macherla 858 views No Comment
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×

In some cases, you want to delete all table data in a fast way and reset all auto increment columns. MySQL provides TRUNCATE table statement to allow you to do so. The SQL TRUNCATE statement is as follows:

TRUNCATE TABLE table_name

There are some points you should remember before using TRUNCATE TABLE statement:

  • TRUNCATE TABLE statement drops table and recreates it therefore it is much faster than DELETE TABLE statement. However it is not transaction-safe.
  • The number of deleted rows is not returned like SQL DELETE TABLE statement.
  • ON DELETE triggers are not invoked because TRUNCATE does not use DELETE statement.
TRUNCATE TABLE emp_table;

Tags: ,