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

N-th Tribonacci Number Solution - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Java Program to Convert Decimal to Binary - The Coding Shala