]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/drop_table.sgml
Create a "sort support" interface API for faster sorting.
[postgresql] / doc / src / sgml / ref / drop_table.sgml
1 <!--
2 doc/src/sgml/ref/drop_table.sgml
3 PostgreSQL documentation
4 -->
5
6 <refentry id="SQL-DROPTABLE">
7  <refmeta>
8   <refentrytitle>DROP TABLE</refentrytitle>
9   <manvolnum>7</manvolnum>
10   <refmiscinfo>SQL - Language Statements</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname>DROP TABLE</refname>
15   <refpurpose>remove a table</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="sql-droptable">
19   <primary>DROP TABLE</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23 <synopsis>
24 DROP TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCADE | RESTRICT ]
25 </synopsis>
26  </refsynopsisdiv>
27
28  <refsect1>
29   <title>Description</title>
30
31   <para>
32    <command>DROP TABLE</command> removes tables from the database.
33    Only the table owner, the schema owner, and superuser can drop a
34    table.  To empty a table of rows
35    without destroying the table, use <xref linkend="sql-delete">
36    or <xref linkend="sql-truncate">.
37   </para>
38
39   <para>
40    <command>DROP TABLE</command> always removes any indexes, rules,
41    triggers, and constraints that exist for the target table.
42    However, to drop a table that is referenced by a view or a foreign-key
43    constraint of another table, <literal>CASCADE</> must be
44    specified. (<literal>CASCADE</> will remove a dependent view entirely,
45    but in the foreign-key case it will only remove the foreign-key
46    constraint, not the other table entirely.)
47   </para>
48  </refsect1>
49
50  <refsect1>
51   <title>Parameters</title>
52
53   <variablelist>
54    <varlistentry>
55     <term><literal>IF EXISTS</literal></term>
56     <listitem>
57      <para>
58       Do not throw an error if the table does not exist. A notice is issued
59       in this case.
60      </para>
61     </listitem>
62    </varlistentry>
63
64    <varlistentry>
65     <term><replaceable class="PARAMETER">name</replaceable></term>
66     <listitem>
67      <para>
68       The name (optionally schema-qualified) of the table to drop.
69      </para>
70     </listitem>
71    </varlistentry>
72
73    <varlistentry>
74     <term><literal>CASCADE</literal></term>
75     <listitem>
76      <para>
77       Automatically drop objects that depend on the table (such as
78       views).
79      </para>
80     </listitem>
81    </varlistentry>
82
83    <varlistentry>
84     <term><literal>RESTRICT</literal></term>
85     <listitem>
86      <para>
87       Refuse to drop the table if any objects depend on it.  This is
88       the default.
89      </para>
90     </listitem>
91    </varlistentry>
92   </variablelist>
93  </refsect1>
94
95  <refsect1>
96   <title>Examples</title>
97
98   <para>
99    To destroy two tables, <literal>films</literal> and
100    <literal>distributors</literal>:
101
102 <programlisting>
103 DROP TABLE films, distributors;
104 </programlisting></para>
105  </refsect1>
106
107  <refsect1>
108   <title>Compatibility</title>
109
110   <para>
111    This command conforms to the SQL standard, except that the standard only
112    allows one table to be dropped per command, and apart from the
113    <literal>IF EXISTS</> option, which is a <productname>PostgreSQL</>
114    extension.
115   </para>
116  </refsect1>
117
118  <refsect1>
119   <title>See Also</title>
120
121   <simplelist type="inline">
122    <member><xref linkend="sql-altertable"></member>
123    <member><xref linkend="sql-createtable"></member>
124   </simplelist>
125  </refsect1>
126
127 </refentry>