You are on page 1of 6

6/6/2020 Difference Between TRUNCATE, DELETE, And DROP In SQL Server

LEARN: How to Become a Software Architect


Difference Between TRUNCATE, DELETE,
Become And DROP
a member
C# Corner Login
In SQL Server Post Ask Question
Jaipal Reddy Updated date, Mar 07, 2020 1.4m 19 25

Download Free .NET & JAVA Files API


Try Free File Format APIs for Word/Excel/PDF
Difference Between TRUNCATE, DELETE And DROP In SQL
 
The di erence between TRUNCATE, DELETE, and DROP is one of the most common interview
questions. TRUNCATE, DELETE, and DROP SQL queries are often used in SQL Server to delete
data from a database. Learn tthe di erence between truncate and delete in SQL.
 
TRUNCATE
 
TRUNCATE SQL query removes all rows from a table, without logging the individual row
deletions. TRUNCATE is faster than the DELETE query.
 
The following example removes all data from the Customers table. 

01. TRUNCATE TABLE Customers;

1. TRUNCATE is a DDL command


2. TRUNCATE is executed using a table lock and the whole table is locked to remove all
records.
3. We cannot use the WHERE clause with TRUNCATE.
4. TRUNCATE removes all rows from a table.
5. Minimal logging in the transaction log, so it is faster performance-wise.
6. TRUNCATE TABLE removes the data by deallocating the data pages used to store the table
data and records only the page deallocations in the transaction log.
7. Identify the column is reset to its seed value if the table contains an identity column.
8. To use Truncate on a table you need at least ALTER permission on the table.
9. Truncate uses less transaction space than the Delete statement.
10. Truncate cannot be used with indexed views.
11. TRUNCATE is faster than DELETE.

DELETE
https://www.c-sharpcorner.com/blogs/difference-between-truncate-delete-and-drop-in-sql-server1 1/6
6/6/2020 Difference Between TRUNCATE, DELETE, And DROP In SQL Server

  LEARN: How to Become a Software Architect


SQL DELETE query deletes all records from a database table. To execute a DELETE query, delete
Become a member
C# Corner Login
permissions are required on the target table. If you need to use a WHERE clause in a DELETE,
select permissions are required as well. Post Ask Question
 
The following query deletes all rows from the Customers table.  

01. DELETE FROM Customers;


02. GO

The following SQL query deletes all rows from the Customers table where OrderID is greater
than 1000. 

01. DELETE FROM Customers WHERE OrderId > 1000;


02. GO

1. DELETE is a DML command.


2. DELETE is executed using a row lock, each row in the table is locked for deletion.
3. We can use where clause with DELETE to lter & delete speci c records.
4. The DELETE command is used to remove rows from a table based on WHERE condition.
5. It maintains the log, so it slower than TRUNCATE.
6. The DELETE statement removes rows one at a time and records an entry in the transaction
log for each deleted row.
7. Identity of column keep DELETE retains the identity.
8. To use Delete you need DELETE permission on the table.
9. Delete uses more transaction space than the Truncate statement.
10. The delete can be used with indexed views.

DROP
 
DROP table query removes one or more table de nitions and all data, indexes, triggers,
constraints, and permission speci cations for those tables. DROP command requires to ALTER
permission on the schema to which the table belongs, CONTROL permission on the table, or
membership in the db_ddladmin xed database role.
 
The following SQL query drops the Customers table and its data and indexes from the current
database. 

01. DROP TABLE Customers ;

1. The DROP command removes a table from the database.


2. All the tables' rows, indexes, and privileges will also be removed.
3. No DML triggers will be red.
4. The operation cannot be rolled back.
5. DROP and TRUNCATE are DDL commands, whereas DELETE is a DML command.

https://www.c-sharpcorner.com/blogs/difference-between-truncate-delete-and-drop-in-sql-server1 2/6
6/6/2020 Difference Between TRUNCATE, DELETE, And DROP In SQL Server

6. DELETE operations
LEARN: can
Howbe rolled back
to Become (undone),
a Software while DROP and TRUNCATE operations
Architect
cannot be rolled back
Become a member
C# Corner Login

Summary Post Ask Question


 
In this post, we saw the di erences between TRUNCATE, DELETE, and DROP SQL commands. We
saw key characteristics of these commands.  We also learn SQL queries with examples. 

Brought to you by: 65+ Blazor Native Components – Try them free. Learn More.

Di erence between TRUNCATE DELETE and DROP in SQL Server

Jaipal Reddy

I am Jaipal Reddy , currently i'm working as Software Engineer on Microsoft Technologies at


Hyderabbad.
https://www.c-sharpcorner.com/members/jaipal-reddy3

510 4.5m

View Previous Comments


25 19

Type your comment here and press Enter Key (Minimum 10 characters)

Good piece of writing. I want to read some more articles written by you. <a
href="https://techleem.com/taylor-alesia/">taylor alesia</a>
David Welson Jun 02, 2020
NA 4 0 0 0 Reply

Well explained !!
Raju Paladiya Feb 21, 2020
1328 543 4.2k 0 0 Reply

DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be
rolled back This statement is wrong. we can rollback TRUNCATE and DROP in a TRANSACTION A link
given below will help you in understanding this. https://www.mssqltips.com/sqlservertip/4591/ddl-
commands-in-transactions-in-sql-server-versus-oracle/
Ranjith Reddy Jan 08, 2020
NA 16 0 0 0 Reply

How to perform two command on the same time like delete the row and update that row as well
rachna choudhary Sep 02, 2019
NA 3 0 0 0 Reply

TRUNCATE TRANSACTION CAN ALSO ROLLED BACK LIKE DELETE.

https://www.c-sharpcorner.com/blogs/difference-between-truncate-delete-and-drop-in-sql-server1 3/6
6/6/2020 Difference Between TRUNCATE, DELETE, And DROP In SQL Server

Javed AlamLEARN: How to Become a Software Architect Jan 09, 2019


NA 56 0 2 0 Reply
Become a member
C# Corner Login

Thanks for sharing Jaipal !!! Post Ask Question


Amit Singh Dec 03, 2018
516 3.6k 108.7k 0 0 Reply

Actually That is gud lecture for lerner peoples. thanks bro.


subba rayudu Oct 25, 2018
NA 2 0 1 0 Reply

Good explanations thank you


Bassem Sarhan Sep 03, 2018
NA 2 0 1 0 Reply

Hi Jaipal Reddy presently am working as fresher in database eld in panjagutta could i know or help
me for any openings in your reputed company.
neeraj sai Aug 28, 2018
NA 61 0 0 2 Reply

Sure Neeraj, I will let you know.


Jaipal Reddy Aug 28, 2018
510 3.7k 4.5m 1

Thank you bro, will be waiting.....


neeraj sai Aug 28, 2018
NA 61 0 0

Great articles....!!!! Thanks for sharing it...!!!


Amol Kumbhkarna Aug 26, 2018
NA 402 0 0 0 Reply

https://www.c-sharpcorner.com/blogs/difference-between-truncate-delete-and-drop-in-sql-server1 4/6
6/6/2020 Difference Between TRUNCATE, DELETE, And DROP In SQL Server

LEARN: How to Become a Software Architect

Become a member
C# Corner Login

Post Ask Question

LATEST BLOGS

Fetching XML Data Through Language Integrated Query In C#

Learn About Copying List, List Fields And List Items Using CSOM

Sets In JavaScript

Show And Hide Password Using jQuery In ASP.NET

Autocomplete Textbox Using jQuery AJAX With Database In ASP.NET

Show Image Preview Before Uploading To Database Using jQuery In ASP.NET

Understanding Association, Aggregation, Composition And Dependency Relationship With UML


Diagram

UML Representation With Scripting

https://www.c-sharpcorner.com/blogs/difference-between-truncate-delete-and-drop-in-sql-server1 5/6
6/6/2020 Difference Between TRUNCATE, DELETE, And DROP In SQL Server

LEARN:
Enable And Remove How to365
Microsoft Become a Software
Search Architect
Bar In SharePoint Online Site Using Powershell
Become a member
C# Corner Login
How To Use Multiple Node.js Versions In Windows OS
Post Ask Question
View All

About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners

C# Tutorials Common Interview Questions Stories Consultants Ideas Certi cations


©2020 C# Corner. All contents are copyright of their authors.

https://www.c-sharpcorner.com/blogs/difference-between-truncate-delete-and-drop-in-sql-server1 6/6

You might also like