SQL Truncate command

SQL Tutorial

[fblike]

SQL TRUNCATE Command : Introduction

  • SQL TRUNCATE Command is a type of SQL DDL command and is used to delete the pre-existing tables from the databases.
  • The difference between SQL DELETE and SQL TRUNCATE Command is, there is no room for deleting specific values/rows from the table with the help of TRUNCATE command. Only the whole table can be deleted and not the specific rows/values.

 

SQL TRUNCATE Command : Syntax

  • The syntax for SQL TRUNCATE command can be depicted as :
This image describes the basic syntax of sql truncate command that can be used in sql.

SQL TRUNCATE Command : Syntax


 

SQL TRUNCATE Command : Example

  • Consider the student_details and teacher_details table over which we need to perform TRUNCATE command.

 

Table : student_details

 

This image describes the select query results.

 

Table : teacher_details

This image describes the select query results.

 

Example-1 : We wish to delete the student_details table. It can be done by executing below query.

Query : TRUNCATE Table student_details;

Output : No table to display(As TRUNCATE table will delete the table).

 

Example-2 : We wish to delete the teacher_details table. It can be done by executing below query.

Query : TRUNCATE Table teacher_details;

Output : No table to display(As TRUNCATE table will delete the table).