SQL DELETE STATEMENT

This statement is used to delete one/more/all rows from the table depending upon some conditions.

Syntax:

DELETE ALL DATA in table without deleting table structure, index, constraints.

DELETE * FROM "tableName";

OR

DELETE FROM "tableName";

Note : Above query will delete all the rows in specified table.

DELETE DATA on the basis of some conditions OR by using where clause.

DELETE FROM "tableName"
WHERE columnName = value;

Note : 1. We can use multiple combination of operators in WHERE clause like (>, >=, <=) greater than, greater than equal to , less than equal to etc.
2. You must remember about foreign key constraints when deleting rows in parent table.

Parameters :

tableName : Name of the table in which we are going to insert data.

columnName, value : They will be used as criteria i.e columnName in the table containing specified value in it.

DELETE with one column : We will be using the same table which we have created in the CREATE TABLE and INSERT STATEMENT

Using Select to see all the records before delete query runs.

SELECT * FROM `employee`;

before-update-query-execution-example1

DELETE FROM `employee` WHERE `id` = 3;

Above query will delete the row which has id 3.

Using Select to see all the records after delete query.

after-delete-query-example1

DELETE with some sql operators is below :

Using Select to see all the records before delete query.

SELECT * FROM `employee`;

after-delete-query-example1

DELEE FROM `employee` WHERE `salary` > 50000 AND `age` = 29 ;

Using Select to see all the records after delete query.

after-delete-query-example2

Tip : we can use multiple combination of operators in WHERE clause..

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *