You are on page 1of 7

Engineering Mathematics Discrete Mathematics Digital Logic and Design Computer Organization and A

Difference between DELETE and TRUNCATE


MKS075

Read Discuss Courses Practice

DELETE is a DML(Data Manipulation Language) command and is used when we


specify the row(tuple) that we want to remove or delete from the table or relation.
The DELETE command can contain a WHERE clause. If the WHERE clause is used
with the DELETE command then it removes or deletes only those rows(tuple) that
satisfy the condition otherwise by default it removes all the tuples(rows) from the
table. Remember that DELETE logs the row deletions.

Syntax: DELETE command

DELETE FROM TableName


WHERE condition;

TRUNCATE is a DDL(Data Definition Language) command and is used to delete all


the rows or tuples from a table. Unlike the DELETE command, the TRUNCATE
command does not contain a WHERE clause. In the TRUNCATE command, the
transaction log for each deleted data page is not recorded. Unlike the DELETE
command, the TRUNCATE command is fast. We cannot roll back the data after
using the TRUNCATE command.

Syntax: TRUNCATE command

TRUNCATE TABLE TableName;

Let us see the difference between DELETE and TRUNCATE commands are as
follows:
Delete Truncate

The DELETE command is used to While this command is used to delete all the
delete specified rows(one or more). rows from a table.

It is a DML(Data Manipulation While it is a DDL(Data Definition Language)


Language) command. command.

There may be a WHERE clause in


While there may not be WHERE clause in
the DELETE command in order to
the TRUNCATE command.
filter the records.

In the DELETE command, a tuple is While in this command, the data page is
locked before removing it. locked before removing the table data.

The DELETE statement removes TRUNCATE TABLE removes the data by


rows one at a time and records an deallocating the data pages used to store the
entry in the transaction log for each table data and records only the page
deleted row. deallocations in the transaction log.

DELETE command is slower than While the TRUNCATE command is faster


TRUNCATE command. than the DELETE command.

To use Delete you need DELETE To use Truncate on a table we need at least
permission on the table. ALTER permission on the table.

The identity of the fewer column


Identity the column is reset to its seed value
retains the identity after using
if the table contains an identity column.
DELETE Statement on the table.

The delete can be used with


Truncate cannot be used with indexed views.
indexed views.

This command can also active


This command does not active trigger.
trigger.
Delete Truncate

DELETE statement occupies more Truncate statement occupies less transaction


transaction spaces than Truncate. spaces than DELETE.

Last Updated : 25 Aug, 2022 96

Similar Reads
1. Difference between DELETE, DROP and TRUNCATE

2. Difference between DROP and TRUNCATE in SQL

3. TRUNCATE() Function in MySQL

4. Truncate All Tables in MySQL

5. SQL | DROP, TRUNCATE

6. Difference between DELETE and DROP in SQL

7. Difference between Set.clear() and Set.delete() Methods in JavaScript

8. Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE


and SELECT

9. new vs malloc() and free() vs delete in C++

10. Difference between Difference Engine and Analytical Engine

Previous Next

Article Contributed By :

MKS075
MKS075
Vote for difficulty
Current difficulty : Easy

Easy Normal Medium Hard Expert

Improved By : MKS075, gbothra38, kumarsanu805128, demishassabis, azamh64, priyansh70890

Article Tags : SQL-Clauses, DBMS, Difference Between, GATE CS, SQL

Practice Tags : DBMS, SQL

Improve Article Report Issue

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

feedback@geeksforgeeks.org

Company Explore
About Us Job Fair For Students

Legal POTD: Revamped

Careers Python Backend LIVE

In Media Android App Development

Contact Us DevOps LIVE

Advertise with us DSA in JavaScript

Languages Data Structures


Python Array

Java String
C++ Linked List

PHP Stack

GoLang Queue

SQL Tree

R Language Graph

Android Tutorial

Algorithms Web Development


Sorting HTML

Searching CSS

Greedy JavaScript

Dynamic Programming Bootstrap

Pattern Searching ReactJS

Recursion AngularJS

Backtracking NodeJS

Computer Science Python


GATE CS Notes Python Programming Examples

Operating Systems Django Tutorial

Computer Network Python Projects

Database Management System Python Tkinter

Software Engineering OpenCV Python Tutorial

Digital Logic Design Python Interview Question

Engineering Maths

Data Science & ML DevOps


Data Science With Python Git

Data Science For Beginner AWS

Machine Learning Tutorial Docker

Maths For Machine Learning Kubernetes

Pandas Tutorial Azure

NumPy Tutorial GCP

NLP Tutorial

Deep Learning Tutorial


Competitive Programming System Design
Top DSA for CP What is System Design

Top 50 Tree Problems Monolithic and Distributed SD

Top 50 Graph Problems Scalability in SD

Top 50 Array Problems Databases in SD

Top 50 String Problems High Level Design or HLD

Top 50 DP Problems Low Level Design or LLD

Top 15 Websites for CP Top SD Interview Questions

Interview Corner GfG School

Company Preparation CBSE Notes for Class 8

Preparation for SDE CBSE Notes for Class 9

Company Interview Corner CBSE Notes for Class 10

Experienced Interview CBSE Notes for Class 11

Internship Interview CBSE Notes for Class 12

Competitive Programming English Grammar

Aptitude

Commerce UPSC

Accountancy Polity Notes

Business Studies Geography Notes

Microeconomics History Notes

Macroeconomics Science and Technology Notes

Statistics for Economics Economics Notes

Indian Economic Development Important Topics in Ethics

Income Tax UPSC Previous Year Papers

Management

SSC/ BANKING Write & Earn

SSC CGL Syllabus Write an Article

SBI PO Syllabus Improve an Article

SBI Clerk Syllabus Pick Topics to Write

IBPS PO Syllabus Write Interview Experience

IBPS Clerk Syllabus Internships


Aptitude Questions Video Internship

SSC CGL Practice Papers

@geeksforgeeks , Some rights reserved

You might also like