Truncate in DBMS

Truncate in DBMS

 

In this article, we will learn about Truncate in DBMS.

Sometimes the user wants to permanently delete the existing table or wants to delete the existing data alone or change the table name all these purposes are served using 3 DDL(data definition language) commands drop, truncate and rename respectively

Truncate in DBMS

TRUNCATE command

  • The truncate command will make the table empty i.e all the table data will be deleted but the structure and database object is still alive and the table can be reused normally
  • The truncate command logically nothing but using delete command for deleting the records in the table without specifying the where condition i.e all the rows get deleted in that case

Syntax

TRUNCATE TABLE table_name;

Example

truncate table emp;
O/P
Table emp truncated successfully
After truncating the table if you try to display the table data using a select statement then you’ll get a message as” 0 rows selected” i.e nothing to display because the table is empty without any rows