SQL TRUNCATE TABLE Statement

This statement is used to delete all rows from the table. Its similar like DELETE statement BUT it does not have WHERE clause in it.

Syntax:

DELETE ALL DATA in table without deleting table structure, index, constraints.

TRUNCATE TABLE "tableName";

Parameters :

tableName : Name of the table which we wish to truncate.

Examples :

We will be using the same table which we have created in the CREATE TABLE and INSERT STATEMENT

Using Select to see all the records before truncate query runs.

SELECT * FROM `employee`;

before-update-query-execution-example1

TRUNCATE TABLE `employee`;

Above query will delete all the rows in the specified table. Its faster than DELETE query.

Using Select to see all the records after delete query. We are using COUNT(*) function to know about numbers of rows in our table.  And its 0 (zero), Which confirms deletion of all rows in the table.

after-truncate-query-example1

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *