Basic Queries  «Prev 

Using SQL DELETE statement


THE DELETE STATEMENT

The version of the DELETE statement that is covered in this module may be one of the easiest statements of them all. Even in the more complex syntax, there is no column list, just a table name and a WHERE clause. The full version looks like this:
DELETE [TOP ( <expression> ) [PERCENT] ] [FROM] <tabular object>
[ OUTPUT <output clause> ]
[FROM <table or join condition>]
[WHERE <search condition> | CURRENT OF [GLOBAL] <cursor name>]
The basic syntax could not be much easier:
DELETE <table name>
[WHERE <condition>]

The WHERE clause works just like all the WHERE clauses you have seen thus far. You do not need to provide a column list because you are deleting the entire row.
(You cannot DELETE half a row, for example; that would be an UPDATE.) Because this is so easy, you can master this by performing only a couple of quick DELETEs that are focused on cleaning up the INSERTs that you performed earlier in the chapter. First, run a SELECT to make sure the fi rst of those rows is still there:
SELECT *
FROM Stores
WHERE StoreCode = "TEST";

1) Here is the BookTable before making the deletion.
1) Here is the BookTable before making the deletion.

2) The complete DELETE statement. This statement will delete all rows that have the titlle.
2) The complete DELETE statement. This statement will delete all rows that have the title Maintaining Your Moped.

3) And here is the table after the DELETE statement executes.
3) And here is the table after the DELETE statement executes.