]> begriffs open source - ai-pg/blob - full-docs/txt/dml-delete.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / dml-delete.txt
1
2 6.3. Deleting Data #
3
4    So far we have explained how to add data to tables and how to change
5    data. What remains is to discuss how to remove data that is no longer
6    needed. Just as adding data is only possible in whole rows, you can
7    only remove entire rows from a table. In the previous section we
8    explained that SQL does not provide a way to directly address
9    individual rows. Therefore, removing rows can only be done by
10    specifying conditions that the rows to be removed have to match. If you
11    have a primary key in the table then you can specify the exact row. But
12    you can also remove groups of rows matching a condition, or you can
13    remove all rows in the table at once.
14
15    You use the DELETE command to remove rows; the syntax is very similar
16    to the UPDATE command. For instance, to remove all rows from the
17    products table that have a price of 10, use:
18 DELETE FROM products WHERE price = 10;
19
20    If you simply write:
21 DELETE FROM products;
22
23    then all rows in the table will be deleted! Caveat programmer.