Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
Difference between DELETE and TRUNCATE
Next article icon

Difference Between DELETE and DROP in SQL

Last Updated : 29 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In SQL, the DELETE and DROP commands are essential for managing data in a database, but they serve different purposes. While both are used to remove data, their functionality varies significantly. The DELETE command is designed to remove specific rows (tuples) or all rows from a table while preserving the table structure. In contrast, the DROP command is used to permanently delete named elements of the schema. Understanding these commands is crucial for effective database management.

This article provides a detailed comparison of these commands, their syntax, examples, and the scenarios where each is best suited. By the end of this article, we will clearly understand how to use DELETE and DROP commands efficiently.

Comparison Between DELETE and DROP Command

Parameter DELETE DROP
Basic It removes some or all the tuples from a table. It removes the entire schema, table, domain, or constraints from the database.
Language Data Manipulation Language command Data Definition Language command.
Clause WHERE clause is mainly used along with the DELETE command. No clause is required along with the DROP command.
Rollback Actions performed by DELETE can be rolled back as it uses a buffer. Actions performed by DROP can’t be rolled back because it directly works on actual data.
Space space occupied by the table in the memory is not freed even if you delete all the tuples of the table using DELETE It frees the table space from memory
Main Issue Shortage of memory Memory fragmentation
Locality of reference Excellent Adequate
Flexibility Fixed-size Resizing is possible

What is DELETE Command in SQL?

The DELETE command is part of SQL’s Data Manipulation Language (DML). It is used to remove specific rows or all rows from a table without deleting the table’s structure. The WHERE clause is often used with DELETE to specify the rows to be removed. If the WHERE clause is skipped, all rows in the table are deleted.

Key Features of DELETE Command

  • Selective Deletion: Deletes specific rows based on a condition.
  • Retention of Structure: The table structure, indexes, and constraints remain intact.
  • Rollback Support: DELETE operations can be rolled back if used within a transaction.

Syntax

DELETE FROM relation_name WHERE condition;

Example: Using the DELETE Command

Step 1: Create a Table and Insert Data

Here, we create a Customer table with CUSTOMERID, FIRST_NAME, LAST_NAME, and AGE.

CREATE TABLE Customer(   CUSTOMERID INT PRIMARY KEY,   FIRST_NAME VARCHAR(50),   LAST_NAME VARCHAR(50),   AGE INT)  INSERT INTO Customer(CUSTOMERID,FIRST_NAME,LAST_NAME,AGE) VALUES (1,'Mohit','Kumar',21), (2,'Praful','Singh',22), (3,'Ritik','Kumar',25), (4,'Vishnu','Yadav',26);

Step 2: View the Data

SELECT * FROM Customer;

Output

Customer Table

Customer Table

Step 3: Delete a Specific Row

If you want to remove some tuples from the Customer Table then we use the DELETE command.

 DELETE FROM Customer where FIRST_NAME='Mohit';

Step 4: View the Updated Data

SELECT * FROM Customer;

Output

Table 1

Table 1

What is DROP Command in SQL?

The DROP command belongs to SQL’s Data Definition Language (DDL). It is used to completely remove database objects such as tables, schemas, or indexes. When a table or object is dropped, it is permanently deleted, including its structure, indexes, and constraints.

Key Features of DROP Command

  • Permanent Deletion: Removes the table or object completely from the database.
  • Frees Memory: Clears the memory space occupied by the table.
  • Irreversible: Once a table is dropped, it cannot be recovered unless a backup exists.

Syntax

  • Drop a Table
DROP TABLE table_name;
  • Drop a Schema
DROP SCHEMA schema_name RESTRICT;

Example: Using DROP Command

Step 1: Drop Customer Table

This command permanently removes the table along with its data, structure, indexes, and constraints.

DROP TABLE Customer; 

Step 2: Drop Database

Drop Database is used to remove the existing SQL Database from the Server.

DROP DATABASE  NAME_OF_DATABASE;

Step 3: DROP COLUMN

The Drop Column is used to remove the existing SQL column from the database.

ALTER TABLE table_nameDrop COLUMN column_name;

Step 4: DROP INDEX

Drop Index is used to remove the index in a table.

DROP INDEX IF EXISTS index_name ON table_name;

Conclusion

The DELETE and DROP commands are both crucial for managing data and database objects in SQL, but they serve different purposes. Use DELETE when we need to remove specific rows or all rows from a table while keeping its structure intact. Choose DROP when we need to permanently delete a table or database object.

Understanding these commands ensures efficient database management and helps maintain data integrity while optimizing storage space. Always back up our data before using the DROP command to avoid unintentional data loss.



Next Article
Difference between DELETE and TRUNCATE

A

Ankit_Bisht
Improve
Article Tags :
  • Databases
  • SQL
  • Technical Scripter

Similar Reads

  • Difference between DELETE, DROP and TRUNCATE
    In SQL, understanding the DELETE, DROP, and TRUNCATE commands is important for efficient data management. While these commands are all used to remove data, they differ significantly in functionality, usage, and performance. Knowing when and how to use each command can improve the efficiency and inte
    4 min read
  • Difference between DROP and TRUNCATE in SQL
    In SQL, the DROP and TRUNCATE commands are used to remove data, but they operate differently. DROP deletes an entire table and its structure, while TRUNCATE removing only the table data. Understanding their differences is important for effective database management. In this article, We will learn ab
    3 min read
  • Difference between DELETE and TRUNCATE
    When managing large datasets in SQL, it's essential to understand the differences between various commands used for removing data. Two commonly used SQL commands for data removal are DELETE and TRUNCATE. While both serve the purpose of removing rows from a table, they have distinct features and use
    5 min read
  • Difference between From and Where Clause in SQL
    1. FROM Clause: It is used to select the dataset which will be manipulated using Select, Update or Delete command.It is used in conjunction with SQL statements to manipulate dataset from source table.We can use subqueries in FROM clause to retrieve dataset from table. Syntax of FROM clause: SELECT *
    2 min read
  • Difference between DDL and TCL
    Prerequisite – SQL Commands 1 Data Definition Language (DDL) is a set of SQL (Structured Query Language) commands used to create, modify, and delete database objects such as tables, indexes, views, and constraints. DDL statements are used to define the schema or structure of a database, including it
    2 min read
  • Difference Between DDL and DML in DBMS
    DDL is a Data Definition Language that is used to define data structures. For example: creating a table, and altering a table are instructions in SQL. DML is a Data Manipulation Language that is used to manipulate data itself. For example: insert, update, and delete are instructions in SQL. Data Def
    3 min read
  • Difference between SQL and T-SQL
    SQL (Structured Query Language) is the standard language for managing and manipulating relational databases, enabling operations like querying, updating, and deleting data. T-SQL (Transact-SQL), an extension of SQL developed by Microsoft, adds advanced features and procedural capabilities specifical
    4 min read
  • Difference Between DML and TCL
    Data Manipulation Language (DML) and Transaction Control Language (TCL) are critical subsets of SQL (Structured Query Language). Both play essential roles in managing and controlling data in a database, but they serve different purposes. In this article, we will explore about the Difference between
    4 min read
  • Difference between Where and Having Clause in SQL
    In SQL, the WHERE and HAVING clauses are essential for filtering data and refining query results. While both serve the purpose of applying conditions, they are used at different stages of query execution and for distinct purposes. Understanding the differences between the WHERE and HAVING clauses is
    4 min read
  • Difference between View and Cursor in SQL
    1. View : A view is a virtual table that not actually exist in the database but it can be produced upon request by a particular user. A view is an object that gives the user a logical view of data from a base table we can restrict to what user can view by allowing them to see an only necessary colum
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences