Loading, please wait...

Truncate Command

How To Use Truncate Command In SQL

 

Introduction:
In this article, you will learn what Truncate command is and how to use Truncate command in SQL.

We use Truncate command for deleting the whole data in the current table. This command is same as delete statement but is not used with where clause. We can also use the drop command for deleting the data but with this command, we delete all the data permanently. If we want to see this data again in our database, we need to store this data again in the database.

 

Truncate Table removes the rows fast and transaction log resources. The main benefit of Truncate table is, when we delete any data from the tables; it loads the identifying data again and returns some to the system to be used in other areas.

 

Here, we have Employee table with some records.

 

 

 

Syntax:

The basic syntax of Truncate table is as follows:

truncate table employee;

 

 

Example:

 

Step 1: First, we write our query for the Truncate table.

 

 

 

Now, select and execute this query.

 

Step 2: The output of this query is-

 

 

 

Summary:
Thus, we learned, Truncate command is used for deleting the whole data in the current table and also learn it's use in SQL.