SQL Truncate a table example – Learn how to delete data from table  in MySQL database with example and important points.

TRUNCAT TABLE statement is used when we want to delete the data completely  from a table without disturbing the table structure. Here are some few important points to note.

  • TRUNCATE command removes the data from the table.
  • It works same as SQL DELETE command without using where condition.
  • Data cannot be rolled back if use truncate command.
  • SQL truncate command works faster and use less resources than Delete command.
  • Truncate command resets auto increment value to zero if the table has auto increment column.
  • Truncate command drops the table and recreates a new table with same structure.

SQL Truncate Table syntax

Syntax:

TRUNCATE TABLE [table_name];

Here is the query to Truncate a table.

Query example:

TRUNCATE TABLE BOOKS;

To get the output use SQL SELECT statement.

Select *  from books.

Output:

empty set <0.00 sec>

Related Posts