1<!-- 2doc/src/sgml/ref/drop_table.sgml 3PostgreSQL documentation 4--> 5 6<refentry id="sql-droptable"> 7 <indexterm zone="sql-droptable"> 8 <primary>DROP TABLE</primary> 9 </indexterm> 10 11 <refmeta> 12 <refentrytitle>DROP TABLE</refentrytitle> 13 <manvolnum>7</manvolnum> 14 <refmiscinfo>SQL - Language Statements</refmiscinfo> 15 </refmeta> 16 17 <refnamediv> 18 <refname>DROP TABLE</refname> 19 <refpurpose>remove a table</refpurpose> 20 </refnamediv> 21 22 <refsynopsisdiv> 23<synopsis> 24DROP 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</literal> must be 44 specified. (<literal>CASCADE</literal> 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 and in turn all objects that depend on those objects 80 (see <xref linkend="ddl-depend"/>). 81 </para> 82 </listitem> 83 </varlistentry> 84 85 <varlistentry> 86 <term><literal>RESTRICT</literal></term> 87 <listitem> 88 <para> 89 Refuse to drop the table if any objects depend on it. This is 90 the default. 91 </para> 92 </listitem> 93 </varlistentry> 94 </variablelist> 95 </refsect1> 96 97 <refsect1> 98 <title>Examples</title> 99 100 <para> 101 To destroy two tables, <literal>films</literal> and 102 <literal>distributors</literal>: 103 104<programlisting> 105DROP TABLE films, distributors; 106</programlisting></para> 107 </refsect1> 108 109 <refsect1> 110 <title>Compatibility</title> 111 112 <para> 113 This command conforms to the SQL standard, except that the standard only 114 allows one table to be dropped per command, and apart from the 115 <literal>IF EXISTS</literal> option, which is a <productname>PostgreSQL</productname> 116 extension. 117 </para> 118 </refsect1> 119 120 <refsect1> 121 <title>See Also</title> 122 123 <simplelist type="inline"> 124 <member><xref linkend="sql-altertable"/></member> 125 <member><xref linkend="sql-createtable"/></member> 126 </simplelist> 127 </refsect1> 128 129</refentry> 130