Learn how to use the SQL TRUNCATE TABLE statement with the explained examples of this tutorial. Remove all the data from the table using SQL TRUNCATE TABLE, you have to specify the table name.

If you want to delete the table along with the data, you can use SQL DROP Table statement.

Because after you execute the truncate code, you may lose all the data in a table. Some people do not prefer to use the statement and delete data single from a table.

How to Use SQL TRUNCATE TABLE to Delete Table Data

To delete the table data using the TRUNCATE TABLE statement, you have to specify only the table name. You will get a blank table after the execution of query using this statement.
Syntax

The details of the single parameter in the above syntax are given below.
Details of Parameters

Sr. No. Parameter Name Sr. No.
1 tablename You have to specify the name of the table whose data you want to delete from the table.

Examples to Delete the Data of a Table Using SQL TRUNCATE TABLE Statement

If you want to delete the table, you can use SQL DROP Table method. the drop table method also deletes the data along with the table.

So, if you want to delete only the data and not the table, always use the SQL TRUNCATE TABLE statement.

Example1: Delete data of table Employee

The above example deletes only the data of the table Employee.
Example2: Delete data of table Student

The above example deletes only the data of the table Student.
You must also learn.

Reference

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.