SQL Delete Row Statement With Example

aimtocode

DELETE statement:

The DELETE statement is used to delete rows from a table.

By using WHERE conditon we can remove any specific row of a table of a database.

Syntax: Using WHERE conditon

  DELETE FROM table_name [WHERE condition];  

Syntax: Without using WHERE conditon

If you do not wish to delete any paritcular row of a table then you can use without WHERE condition and can delete the row of table.

DELETE FROM table_name;

It is possible to remove or erase the table row in such a way, 1). DELETE statement, 2). DROP statement and TRUNCATE statement.


Syntax: delete

DELETE FROM table_name
WHERE [condition];

You can even combine 'n' numbers of conditions using AND or OR Operators.

Example:

Let's Assume we are have a table like this:

ID NAME AGE ADDRESS SALARY
01 PRAYAG 21 RANCHI 36000
02 PANKAJ 24 DELHI 24000
03 SATANAND 24 MUMBAI 16000
04 RAKESH 25 CHENNAI 56000
05 SUJEET 19 GIRIDIH 18000
06 PRAKASH 25 ORISHA 25000

Now Let's delete a row using SQL DELETE query whose ID is 6.

SQL> DELETE FROM CUSTOMERS
WHERE ID = 6;
--------------
1 row deleted;

Result:

ID NAME AGE ADDRESS SALARY
01 PRAYAG 21 RANCHI 36000
02 PANKAJ 24 DELHI 24000
03 SATANAND 24 MUMBAI 16000
04 RAKESH 25 CHENNAI 56000
05 SUJEET 19 GIRIDIH 18000
aimtocode