Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

TRUNCATE Statement in SQL

TRUNCATE is a type of DDL Command. The TRUNCATE SQL command removes all the mentioned rows from any table without the use of any condition. TRUNCATE TABLE typically deletes all records in a table quickly by deallocating the data pages that are used by the table. It reduces the resource overhead created by logging the deletions along with the total number of locks acquired. The records that are removed this way can never be restored in the case of a rollback operation.

In this article, we will dive deeper into the TRUNCATE Statement in SQL according to the GATE Syllabus for (Computer Science Engineering) CSE. Keep reading ahead to learn more.

Table of Contents

What is a TRUNCATE Statement in SQL?

The TRUNCATE statement is a DDL (Data Definition Language) operation used to mark to what extent a table can be deallocated or made empty for reuse. The result of the TRUNCATE operation basically removes all data from a table quickly, typically bypassing various integrity enforcing mechanisms. And it was introduced officially in the SQL:2008 standard.

Remember that the statement of a TRUNCATE TABLE mytable is logically (not physically) equivalent to that of the DELETE FROM mytable statement (existing without a WHERE clause).

Syntax

The Syntax of the TRUNCATE statement goes like this:

TRUNCATE TABLE name_of_table;

where,

name_of_table: The name of the table that is to be truncated.

DATABASE name – data_of_student

Example

In order to truncate the details_of_students table from a database student_data, we use:

TRUNCATE TABLE details_of_student;

After running the query mentioned above, the table details_of_student table will be truncated, meaning the data will be deleted. However, the structure would still remain in the memory in order to perform further operations in the future.

Properties of TRUNCATE Statement in SQL

  • Normally, TRUNCATE is ultra-fast. It is ideal to delete data and information from a temporary table.
  • The TRUNCATE command preserves the table’s structure for future use, unlike the DROP table, which deletes the table with its full structure.

Keep learning and stay tuned to get the latest updates on the GATE Exam along with Eligibility Criteria, GATE Syllabus for CSE (Computer Science Engineering), GATE CSE Notes, GATE CSE Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*