The SQL DELETE Clause is used to delete rows in a table.
With some condition being set with the DELETE clause, all data that meet the condition will be deleted.
DELETE is not limited to one row at a time. We may delete any or all rows that apply to our conditional together.
The DELETE clause syntax:
DELETE FROM [TABLE NAME]
WHERE [COLUMN NAME] = [CONDITION]
EXAMPLE :
We can try to DELETE the records for Player Kenny in the table below.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
Vivian | Marketing | 2500 |
Kenny | HR | 2300 |
SQL statement :
DELETE FROM GameScores
WHERE PlayerName = 'Kenny'
After execute the SQL command. The table will look like like this. As we can see the record for Kenny already Deleted.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
Vivian | Marketing | 2500 |
If you wish to DELETE all rows inside a table.
The SQL Statement will be like this:
DELETE FROM GameScores