3 PostgreSQL documentation
6 <refentry id=
"SQL-DROPTABLE">
8 <refentrytitle id=
"SQL-DROPTABLE-TITLE">DROP TABLE
</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements
</refmiscinfo>
14 <refname>DROP TABLE
</refname>
15 <refpurpose>remove a table
</refpurpose>
18 <indexterm zone=
"sql-droptable">
19 <primary>DROP TABLE
</primary>
24 DROP TABLE [ IF EXISTS ]
<replaceable class=
"PARAMETER">name
</replaceable> [, ...] [ CASCADE | RESTRICT ]
29 <title>Description
</title>
32 <command>DROP TABLE
</command> removes tables from the database.
33 Only its owner can drop a table. To empty a table of rows
34 without destroying the table, use
<xref linkend=
"sql-delete"
35 endterm=
"sql-delete-title"> or
<xref linkend=
"sql-truncate"
36 endterm=
"sql-truncate-title">.
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.)
51 <title>Parameters
</title>
55 <term><literal>IF EXISTS
</literal></term>
58 Do not throw an error if the table does not exist. A notice is issued
65 <term><replaceable class=
"PARAMETER">name
</replaceable></term>
68 The name (optionally schema-qualified) of the table to drop.
74 <term><literal>CASCADE
</literal></term>
77 Automatically drop objects that depend on the table (such as
84 <term><literal>RESTRICT
</literal></term>
87 Refuse to drop the table if any objects depend on it. This is
96 <title>Examples
</title>
99 To destroy two tables,
<literal>films
</literal> and
100 <literal>distributors
</literal>:
103 DROP TABLE films, distributors;
109 <title>Compatibility
</title>
112 This command conforms to the SQL standard, except that the standard only
113 allows one table to be dropped per command, and apart from the
114 <literal>IF EXISTS<
/> option, which is a
<productname>PostgreSQL<
/>
120 <title>See Also
</title>
122 <simplelist type=
"inline">
123 <member><xref linkend=
"sql-altertable" endterm=
"sql-altertable-title"></member>
124 <member><xref linkend=
"sql-createtable" endterm=
"sql-createtable-title"></member>