The DELETE statement is used to delete rows in a table.
DELETE FROM tableName WHERE columnName = someValue; |
From this "Books" table:
Title |
Author |
Publisher |
Year |
الدورة الدموية |
إبن النفيس |
دار العلم |
1650 |
Java 2 |
L. Johnston |
Fast Press |
2002 |
Linux and Unix |
J. Sam |
Fast Press |
2004 |
Linux Distributions |
J. Sam |
Fast Press |
2003 |
Operating Systems |
M. Stone |
Coriolis |
2005 |
Web Programming |
K. Yariv |
East Edition |
2006 |
XML Language |
M. Salim |
Knowledge Press |
2000 |
The book having the title "Linux Distributions" is going to be deleted:
DELETE FROM Books WHERE Title = 'Linux Distributions'; |
The result is:
Title |
Author |
Publisher |
Year |
الدورة الدموية |
إبن النفيس |
دار العلم |
1650 |
Java 2 |
L. Johnston |
Fast Press |
2002 |
Linux and Unix |
J. Sam |
Fast Press |
2004 |
Operating Systems |
M. Stone |
Coriolis |
2005 |
Web Programming |
K. Yariv |
East Edition |
2006 |
XML Language |
M. Salim |
Knowledge Press |
2000 |
It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:
DELETE FROM tableName; |
To test your SQL skills click here.