バージョンごとのドキュメント一覧

6.3. データの削除 #

<title>Deleting Data</title>

So far we have explained how to add data to tables and how to change data. What remains is to discuss how to remove data that is no longer needed. Just as adding data is only possible in whole rows, you can only remove entire rows from a table. In the previous section we explained that SQL does not provide a way to directly address individual rows. Therefore, removing rows can only be done by specifying conditions that the rows to be removed have to match. If you have a primary key in the table then you can specify the exact row. But you can also remove groups of rows matching a condition, or you can remove all rows in the table at once. これまで、テーブルにデータを追加する方法と、データを変更する方法について説明してきました。 残っているのは不要になったデータを削除する方法です。 データの追加が行単位でしか行えないのと同様、削除の場合も、行全体をテーブルから削除するしかありません。 前節で、SQLでは個々の行を直接指定する方法がないということを説明しました。 ですから行の削除の場合も、削除対象となる行の条件を指定することでしかできません。 テーブルに主キーが設定されている場合は、その行を正確に指定できます。 しかし、条件を満たす複数の行、あるいは、テーブル内の全ての行を一度に削除することもできます。

You use the <xref linkend="sql-delete"/> command to remove rows; the syntax is very similar to the <xref linkend="sql-update"/> command. For instance, to remove all rows from the products table that have a price of 10, use: 行を削除するには、DELETEコマンドを使用します。 構文はUPDATEコマンドによく似ています。 例えば、productsテーブルから価格が10である全ての行を削除するには以下のようにします。

DELETE FROM products WHERE price = 10;

If you simply write: 単に次のようにすると、テーブル内の全ての行が削除されますので注意してください!

DELETE FROM products;

then all rows in the table will be deleted! Caveat programmer. プログラマに対する警告です。