The Delete Statement

The DELETE statement allows you to remove one or more records from a table. The basic syntax of the DELETE statement is the following:

DELETE FROM table_name [WHERE restriction_condition]

As with the UPDATE statement, notice that the WHERE clause is optional. This is probably more dangerous in the case of the DELETE statement, however, because executing a DELETE statement without a WHERE clause will delete every single record in the specified table. Once again, there is no way to undo this, so be very careful. You should always include a WHERE clause in your DELETE statements unless you have some very specific reason for wanting to remove all records from a table.

Assume that, for some reason, an entry was made into the Customers table with the ID value of 30 by mistake (maybe they were a supplier rather than a customer). To remove this record from the Customers table, you would use the following DELETE statement:

DELETE FROM Customers WHERE ID = 3 0

Once again, because you used the record's primary key in the WHERE clause, only that specific record will be affected by the DELETE statement.

0 0

Post a comment