H2 Database 简明教程

H2 Database - Drop

DROP 是从通用 SQL 语法中获取的命令。此命令用于从内存中删除数据库组件及其结构。本章将讨论使用 Drop 命令的不同情况。

DROP is a command taken from the generic SQL grammar. This command is used to delete a database component and its structure from the memory. There are different scenarios with the Drop command that we will discuss in this chapter.

Drop Table

Drop Table 是一个删除相应表及其结构的命令。

Drop Table is a command that deletes the respective table and its structure.

Syntax

以下是 Drop Table 命令的通用语法。

Following is the generic syntax of the Drop Table command.

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

如果我们正在使用 RESTRICT 并且该表具有从属视图,则该命令将失败。当我们使用 CASCADE 关键字时,所有从属视图都将被删除。

The command will fail if we are using RESTRICT and the table having dependent views exist. All dependent views are dropped, when we are using CASCADE keyword.

Example

在此示例中,我们将使用以下查询删除名为 test 的表。

In this example, we will drop a table named test using the following query.

DROP TABLE test;

以上查询将产生以下输出。

The above query produces the following output.

(6) row (s) effected

Drop Schema

Drop Schema 是一条从数据库服务器删除相应模式的命令。它不会在当前模式中运行。

Drop Schema is a command that drops a respective schema from the database server. It will not work from the current schema.

Syntax

DROP SCHEMA [ IF EXISTS ] schemaName

Example

在此示例中,我们将使用以下查询删除名为 test_schema 的模式。

In this example, we will drop a schema named test_schema using the following query.

DROP SCHEMA TEST_SCHEMA;

以上查询将产生以下输出。

The above query produces the following output.

(0) row(s) effected

Drop Sequence

Drop Sequence 是一条用于从表结构中删除序列的命令。

Drop Sequence is a command used to drop a sequence from the table structure.

Syntax

以下是 Drop Sequence 命令的通用语法。

Following is the generic syntax of the Drop Sequence command.

DROP SEQUENCE [ IF EXISTS ] sequenceName

此命令会提交此连接中的未决事务。

This command commits an open transaction in this connection.

Example

在此示例中,我们将删除名为 sequence_id 的序列。以下是该命令。

In this example, we will drop a sequence named sequence_id. Following is the command.

DROP SEQUENCE sequence_id;

以上命令会产生以下输出。

The above command produces the following output.

(0) row (s) effected

Drop View

Drop View 是一条用于删除现有视图的命令。如果使用了 CASCADE 子句,所有依赖的视图也会被删除。

Drop View is a command used to drop the existing view. All dependent views are dropped as well if the CASCADE clause is used.

Syntax

以下是 Drop View 命令的通用语法。

Following is the generic syntax of the Drop View command.

DROP VIEW [ IF EXISTS ] viewName [ RESTRICT | CASCADE ]

Example

在此示例中,我们将使用以下查询删除名为 sample_view 的视图。

In this example, we will drop a view named sample_view using the following query.

DROP VIEW sample_view;

以上查询将产生以下输出。

The above query produces the following output.

(0) row (s) effected