SQL Delete
This tutorial will demonstrate how to DELETE records from a database table.
The SQL DELETE statement is used when you want to delete record(s) from your table.
In this tutorial there is two SQL DELETE examples:
SQL DELETE EXAMPLE
SQL DELETE Syntax
WHERE “condition”
To demonstrate the above example assume that we have the following table called Games
| ID | Title | Release Date | Genres | Platform |
|---|---|---|---|---|
| 1001 | GTA IV | April 29, 2008 | Action-adventure | PS3,XBOX360 |
| 1002 | Gran Turismo 5 | November 24, 2010 | Racing | PS3 |
| 1003 | Assassin’s Creed | November 14, 2007 | Third person | PS3,XBOX360 |
| 1004 | Battlefield: Bad Company | June 26, 2008 | First person shooter | PS3,XBOX360 |
| 1005 | LittleBigPlanet | October 01, 2008 | Puzzle platformer | PS3 |
| 1006 | Fifa 11 | October 01, 2010 | Sports | PS3,XBOX360,WII |
| 1007 | LittleBigPlanet 2 | January 21, 2011 | Adventure | PS3,XBOX360 |
| 1008 | Dead Space 2 | January 28, 2011 | Third person | PS3,XBOX360 |
| 1009 | Mindjack | January 28, 2011 | Third person | XBOX360 |
| 1010 | Mario Sports Mix | Febuary 04, 2011 | Adventure | WII |
To DELETE one of the records we added in the SQL INSERT tutorial, we would use the following query:
WHERE ID=1006
Once executed the resultset would look like this:
| ID | Title | Release Date | Genres | Platform |
|---|---|---|---|---|
| 1001 | GTA IV | April 29, 2008 | Action-adventure | PS3,XBOX360 |
| 1002 | Gran Turismo 5 | November 24, 2010 | Racing | PS3 |
| 1003 | Assassin’s Creed | November 14, 2007 | Third person | PS3,XBOX360 |
| 1004 | Battlefield: Bad Company | June 26, 2008 | First person shooter | PS3,XBOX360 |
| 1005 | LittleBigPlanet | October 01, 2008 | Puzzle platformer | PS3 |
| 1007 | LittleBigPlanet 2 | January 21, 2011 | Adventure | PS3,XBOX360 |
| 1008 | Dead Space 2 | January 28, 2011 | Third person | PS3,XBOX360 |
| 1009 | Mindjack | January 28, 2011 | Third person | XBOX360 |
| 1010 | Mario Sports Mix | Febuary 04, 2011 | Adventure | WII |
SQL DELETE ALL EXAMPLE
SQL DELETE Syntax
To demonstrate the above example assume that we have the following table called Games
| ID | Title | Release Date | Genres | Platform |
|---|---|---|---|---|
| 1001 | GTA IV | April 29, 2008 | Action-adventure | PS3,XBOX360 |
| 1002 | Gran Turismo 5 | November 24, 2010 | Racing | PS3 |
| 1003 | Assassin’s Creed | November 14, 2007 | Third person | PS3,XBOX360 |
| 1004 | Battlefield: Bad Company | June 26, 2008 | First person shooter | PS3,XBOX360 |
| 1005 | LittleBigPlanet | October 01, 2008 | Puzzle platformer | PS3 |
| 1007 | LittleBigPlanet 2 | January 21, 2011 | Adventure | PS3,XBOX360 |
| 1008 | Dead Space 2 | January 28, 2011 | Third person | PS3,XBOX360 |
| 1009 | Mindjack | January 28, 2011 | Third person | XBOX360 |
| 1010 | Mario Sports Mix | Febuary 04, 2011 | Adventure | WII |
To DELETE all of the records we would use the following query:
Once executed the resultset would look like this:
| ID | Title | Release Date | Genres | Platform |
|---|
Give it a go and once you feel comfortable using the SQL DELETE keyword move on to our next tutorial SQL OPERATORS.