<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>6.3. Deleting Data</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="dml-update.html" title="6.2. Updating Data" /><link rel="next" href="dml-returning.html" title="6.4. Returning Data From Modified Rows" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">6.3. Deleting Data</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="dml-update.html" title="6.2. Updating Data">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="dml.html" title="Chapter 6. Data Manipulation">Up</a></td><th width="60%" align="center">Chapter 6. Data Manipulation</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 11.5 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="dml-returning.html" title="6.4. Returning Data From Modified Rows">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="DML-DELETE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">6.3. Deleting Data</h2></div></div></div><a id="id-1.5.5.5.2" class="indexterm"></a><a id="id-1.5.5.5.3" class="indexterm"></a><p> 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. </p><p> You use the <a class="xref" href="sql-delete.html" title="DELETE"><span class="refentrytitle">DELETE</span></a> command to remove rows; the syntax is very similar to the <code class="command">UPDATE</code> command. For instance, to remove all rows from the products table that have a price of 10, use: </p><pre class="programlisting"> DELETE FROM products WHERE price = 10; </pre><p> </p><p> If you simply write: </p><pre class="programlisting"> DELETE FROM products; </pre><p> then all rows in the table will be deleted! Caveat programmer. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="dml-update.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="dml.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="dml-returning.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6.2. Updating Data </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 6.4. Returning Data From Modified Rows</td></tr></table></div></body></html>