[Previous] [Contents] [Next]


Deleting Data

There is an important distinction between dropping and deleting in SQL. DROP is used to remove tables or databases; DELETE is used to remove data.

The statement:

DELETE FROM customer;

deletes all data in the customer table but doesn't remove the table. In contrast, dropping the table removes the data and the table.

A DELETE statement with a WHERE clause can remove specific rows; WHERE clauses are frequently used in querying, and they are explained later in Section 3.8.3. Consider a simple example:

DELETE FROM customer WHERE cust_id = 1;

This deletes the customer with cust_id=1. Consider another example:

DELETE FROM customer WHERE surname = 'Smith';

This removes all rows for customers with the surname Smith.


[Previous] [Contents] [Next]