EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Login
Home Data Science Data Science Tutorials SQL Tutorial SQL DELETE

SQL DELETE

Updated March 15, 2023

SQL DELETE

Introduction to SQL DELETE

SQL delete is used to delete the records from the table. We can use the where clause with the delete statement to delete the selected records from the table. Suppose we have not used any condition in our query all the records from the table are deleted. The SQL delete is a DML query that allows the modification of database tables; it will delete the existing rows from the database tables.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Overview of SQL DELETE

  • We need to be careful while executing this command because it will delete the records from the table.
  • As we know, we are using inset statements in SQL for inserting statements. Same for deleting records from the table, we are using the delete statement.
  • We can delete the table rows as per the condition that we have used in the query by using the delete statement.
  • When deleting records from table, we can use more than one condition in a single query, the records will be deleted as per the condition.

SQL DELETE Statement

  • This statement is used to delete the existing records from the table. We need to define the table name from which we have deleted the records.
  • In the below first syntax, we have not used the where condition, so all the records from a table will be deleted. In the fourth syntax, we have used only on where condition, so all the rows will be deleted that match this condition. In the second syntax, we use two conditions with a where clause, so data is deleted at the time matching both the conditions.

Syntax

Delete from name_of_table;
Delete from name_of_table where name_of_column1 = value AND name_of_column = values;
Delete from name_of_table where name_of_column <comparison operator> values;
Delete from name_of_table where condition;

Below is the parameter description of syntax.

  • Delete – This statement is used to delete the rows from a table. We can use the delete statement with and without where condition to delete rows from the table.
  • From – This is the SQL keyword used to define the table name from which we deleted the records.
  • Name of table – This is nothing but the table name from which we have deleted the records. When deleting records or executing a query, we need to define the table name.
  • Where condition – This is the most important parameter at the time of execution. The where condition in the delete statement of SQL will be used to delete the specified row which we have defined in the where condition. Where condition is very useful to delete specific condition row using the sql delete statement.
  • Name of column – This table column is used to delete data from a table. Suppose we have used the delete statement with a specified column it will be deleting the records from the table.
  • AND – This keyword is used in the delete statement to delete the rows from the specified column that we have defined in the query.
  • When using a single column in the where condition, the delete query will be deleting the specified row that matches the condition.

SQL DELETE Query

  • SQL delete query is not case sensitive we can use DELETE or delete to execute the sql delete query.
  • The below example shows that the query is not case sensitive. In the first example, we have used sql delete query in the lowercase letter; after using sql delete query, it will execute without issuing any error. In the second example, we have used sql delete query in the uppercase letter; after using a delete query in the uppercase letter, it will also execute without issuing any error. So we can say that the SQL delete query is not case sensitive.
delete from sql_insert where id = 1001;
DELETE from sql_insert where id = 1001;

SQL DELETE - Image 1

  • When executing any delete query on the production database server, we need to be very careful because it may take downtime of the system.
  • Suppose our application needs to contain only new records, and we need to delete old records at the same time; we can use this statement to delete old records from the table.
  • We can also use the comparison operator to delete the records from a table; after using the comparison operator, the matched rows will be deleted.
Select * from sql_delete;
Select * from sql_delete1;

SQL DELETE - Image 2

  1. In the below example, we deleted the specified records using the where condition. We have used the where condition on the id column. We can see that two records will be deleted because where condition will match the two rows.
DELETE from sql_delete1 where id = 1001;
Select * from sql_delete1;

SQL DELETE - Image 3

2. In the below example we are using a two-column with where condition to delete records from a table. We are using the id and stud_grade column with the where condition.

DELETE from sql_delete1 where id = 1002 and stud_grade = 1;
Select * from sql_delete1;

Image 4

3. In the below example we are using the comparison operator to delete the records from a table. We are using the>, < and = operator to delete the records.

DELETE from sql_delete1 where id > 1005;
DELETE from sql_delete1 where id < 1003;
DELETE from sql_delete1 where id = 1004;
Select * from sql_delete1;

Image 5

4. In the below example we are deleting the records as per the varchar data type column as follows.

Delete from sql_delete1 where stud_name = 'ABC';
Select * from sql_delete1;

Image 6

5. In the below example we are deleting whole the records from the sql_delete1 table as follows.

Delete from sql_delete1;
Select * from sql_delete1;

Image 7

Conclusion

To delete the whole records from the table, we do not need to use any other condition while executing the delete query; we need to use only the table name with the delete query. SQL delete query is a handy and important command in SQL database to delete the unwanted records from the table.

Recommended Article

We hope that this EDUCBA information on “SQL DELETE” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PL/SQL TO_CHAR
  2. PL/SQL varray
  3. PL/SQL NOT EQUAL
  4. SQL WAITFOR
ADVERTISEMENT
All in One Excel VBA Bundle
500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
Financial Analyst Masters Training Program
2000+ Hours of HD Videos
43 Learning Paths
550+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Data Science Bundle
2000+ Hour of HD Videos
80 Learning Paths
400+ Courses
Verifiable Certificate of Completion
Lifetime Access
ADVERTISEMENT
All in One Software Development Bundle
5000+ Hours of HD Videos
149 Learning Paths
1050+ Courses
Verifiable Certificate of Completion
Lifetime Access
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Extended Cyber Monday Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW