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

DROP TABLE

DROP TABLE <refpurpose>remove a table</refpurpose> — テーブルを削除する

概要

DROP TABLE [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]

説明

<title>Description</title>

<command>DROP TABLE</command> removes tables from the database. Only the table owner, the schema owner, and superuser can drop a table. To empty a table of rows without destroying the table, use <link linkend="sql-delete"><command>DELETE</command></link> or <link linkend="sql-truncate"><command>TRUNCATE</command></link>. DROP TABLEはデータベースからテーブルを削除します。 テーブル所有者、スキーマ所有者、スーパーユーザのみがテーブルを削除することができます。 テーブルを削除するのではなく、テーブルの行を空にするには、DELETEまたはTRUNCATEを使用してください。

<command>DROP TABLE</command> always removes any indexes, rules, triggers, and constraints that exist for the target table. However, to drop a table that is referenced by a view or a foreign-key constraint of another table, <literal>CASCADE</literal> must be specified. (<literal>CASCADE</literal> will remove a dependent view entirely, but in the foreign-key case it will only remove the foreign-key constraint, not the other table entirely.) DROP TABLEは、削除対象のテーブルについて存在するインデックス、ルール、トリガ、制約を全て削除します。 しかし、ビューや他のテーブルの外部キー制約によって参照されているテーブルを削除するにはCASCADEを指定する必要があります (CASCADEを指定すると、テーブルに依存するビューは完全に削除されます。外部キー制約によって参照されている場合は、外部キー制約のみが削除され、その外部キーを持つテーブルそのものは削除されません)。

パラメータ

<title>Parameters</title>
IF EXISTS

Do not throw an error if the table does not exist. A notice is issued in this case. テーブルが存在しない場合でもエラーになりません。 この場合、注意メッセージが発行されます。

name

The name (optionally schema-qualified) of the table to drop. 削除するテーブルの名前です(スキーマ修飾名も可)。

CASCADE

Automatically drop objects that depend on the table (such as views), and in turn all objects that depend on those objects (see <xref linkend="ddl-depend"/>). 削除するテーブルに依存しているオブジェクト(ビューなど)を自動的に削除し、さらにそれらのオブジェクトに依存するすべてのオブジェクトも削除します(5.14参照)。

RESTRICT

Refuse to drop the table if any objects depend on it. This is the default. 依存しているオブジェクトがある場合に、テーブルの削除を拒否します。 こちらがデフォルトです。

<title>Examples</title>

To destroy two tables, <literal>films</literal> and <literal>distributors</literal>: 2つのテーブル、filmsdistributorsを削除します。

DROP TABLE films, distributors;

互換性

<title>Compatibility</title>

This command conforms to the SQL standard, except that the standard only allows one table to be dropped per command, and apart from the <literal>IF EXISTS</literal> option, which is a <productname>PostgreSQL</productname> extension. 標準では1コマンドで1テーブルのみを削除できるという点、および、PostgreSQLの拡張であるIF EXISTSオプションを除き、このコマンドは標準SQLに従います。

関連項目

<title>See Also</title> ALTER TABLE, CREATE TABLE