If you want to remove rows from a database table you can use the DELETE SQL command. Here is how to do it:


Before you run to your computer and run the statement above a word of warning - DON'T! If you run the statement above it will delete all rows in the table Cars and you will end up with an empty table. So how do I delete a limited number of rows then, you might ask? The answer to this is simple, and we will do it with the help of the WHERE clause from the previous chapter. When deleting data the WHERE clause is used in the same manner we used it with the SELECT command. For example to delete all cars that are Silver in color, you need to execute the following SQL statement:

DELETE FROM Cars WHERE Color = 'Silver';

Here's what you'll get if select everything from Cars after the above DELETE statement has been executed:

HondaAccord EX2002Black
BMW3 Series Coupe2009NULL

Keep in mind that you cannot undo a DELETE operation, that's why you have to be very cautious when using this powerful SQL command.