Sams Teach Yourself SQL in 24 Hours

Sams Teach Yourself SQL in 24 Hours

By Ron Plew and Ryan Stephens

Deleting Data from Tables

The DELETE command is used to remove entire rows of data from a table. The DELETE command is not used to remove values from specific columns; a full record, including all columns, is removed. The DELETE statement must be used with caution—as it works all too well. The next section discusses methods for deleting data from tables.

To delete a single record or selected records from a table, the DELETE statement must be used with the following syntax:

   syntax_icon.gif
delete from table_name
[where condition];input_icon.gif

   DELETE FROM ORDERS_TBL

   WHERE ORD_NUM = '23A16';
   output_icon.gif
1 row deleted.

Notice the use of the WHERE clause. The WHERE clause is an essential part of the DELETE statement if you are attempting to remove selected rows of data from a table. You rarely issue a DELETE statement without the use of the WHERE clause. If you do, your results will be similar to the following example:

DELETE FROM ORDERS_TBL; 

11 rows deleted.

Share ThisShare This

Informit Network