SQL DELETE Statement

The SQL DELETE statement is used to delete records that already exist in a table. We can use the WHERE clause with the DELETE statement to delete the selected rows, otherwise all records will be deleted.

DELETE Statement Syntax :

The syntax of the DELETE statement is −

DELETE FROM table-name WHERE condition;
   

In this, records that satisfying the WHERE condition are to be deleted.



DELETE Statement Example :

Consider the Customer table with the following records -

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
4 Muhammad 24 Udaipur 50000
5 Sai 30 Mumbai 27000


TEST CASE 1 :- The following code is an example, which would delete the record from Customer table where CustomerName='Sai'.

DELETE FROM Customer WHERE CustomerName='Sai';
   


The result for the respective sql query is as follows −

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
4 Muhammad 24 Udaipur 50000



TEST CASE 2:- The following code is an example, which would delete all the records from Customer table.

DELETE FROM Customer;
   


The result for the respective sql query is as follows −
You have changed the database. All records have been deleted from the customer table.





Visit :


Discussion


* You must be logged in to add comment.