SQL DELETE QUERY - The Coding Shala

Home >> Learn SQL >> SQL DELETE QUERY

SQL DELETE QUERY 

The SQL 'DELETE' Query is used to delete existing rows from a table. We can use the 'WHERE' clause with 'DELETE' to delete the selected row if we don't use 'Where' then it will delete all the rows from a table. 
SQL DELETE QUERY - The Coding Shala

SQL DELETE QUERY SYNTAX 

The basic SQL DELETE query syntax is as follows - 
 DELETE FROM table_name  
 WHERE condition;  

SQL DELETE QUERY EXAMPLES 

The following table Persons contains - 

PersonID     LastName     FirstName     Address     City  
 1          Saini          Akshay          A-101     Pune  
 2           last           first          A-101     Pune  
 3           null           Nikhil           null     null

The following query will delete a row that has PersonID is 3 - 

SQL >> delete from Persons  
        where  
       PersonID = 3  
 
Output >>  
 PersonID     LastName     FirstName     Address     City  
 1          Saini          Akshay        A-101     Pune  
 2           last           first       A-101     Pune  

  • The following query will delete all the records from the 'Persons' table - 
 delete * from Persons


Other Posts You May Like
Prev<< SQL UPDATE QUERY                                                                  NEXT >>SQL Alter Table
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Java Program to Convert Binary to Decimal - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

LeetCode - Shuffle the Array Solution - The Coding Shala

Java Program to Find GCD or HCF of Two Numbers - The Coding Shala