下拉序列

下拉序列 “删除序列

句法

DROP SEQUENCE [ IF EXISTS ] [schema.]sequence_name
DROP SEQUENCE  [schema.]sequence_name [ IF EXISTS ]

描述

Use the 下拉序列 statement to remove a sequence from the database. You cannot drop a sequence that is defined as the sequence of a generated by identity table column (see 例1)。您还可以使用此语句通过删除然后重新创建序列来重新启动序列。

丢弃列或表时,为自动化列创建的序列会自动丢弃。

参数

IF EXISTS

If the sequence does not exist and you specify I F EXISTS, NuoDB does not generate an error. Otherwise, if the sequence does not exist, an error is generated. IF EXISTS may be specified either before or after the sequence name.

schema

可选的。拥有要删除的序列的架构的名称。如果未提供架构,则序列必须由当前模式拥有。

sequence_name

可选的。拥有要删除的序列的架构的名称。如果未提供架构,则序列必须由当前模式拥有。

例子

示例1:尝试删除定义为表列的序列的序列。
用 TEST;
CREATE SEQUENCE tst_seq START WITH 10;
CREATE TABLE tst_table
       (id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY (tst_seq)
       ,column1 string);
 INTO tst_table (column1) VALUES ('column1 string value');
DROP SEQUENCE tst_seq;
sequence "TEST.TST_SEQ" is referenced by table TEST.TST_TABLE and cannot be dropped

DROP TABLE tst_table;
DROP SEQUENCE tst_seq;
示例2:删除不存在的序列
DROP SEQUENCE IF EXISTS nosuchsequence;
DROP SEQUENCE nosuchsequence IF EXISTS;
示例3:当表删除时,将创建的序列自动删除
用 TEST;
CREATE TABLE tst_table
       (id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY
       ,column1 string);
 INTO tst_table (column1) VALUES ('column1 string value');
表演 TABLE tst_table;
    Found table TST_TABLE in schema TEST

        Fields:
            ID integer
                Nullable: No
                Generator: TST_TABLE$IDENTITY_SEQUENCE    Generated Always
            COLUMN1 string
        Primary Index: TST_TABLE..PRIMARY_KEY on field: ID

DROP SEQUENCE TST_TABLE$IDENTITY_SEQUENCE;
sequence "TEST.TST_TABLE$IDENTITY_SEQUENCE" is referenced by table TEST.TST_TABLE and cannot be dropped

DROP TABLE tst_table;
DROP SEQUENCE TST_TABLE$IDENTITY_SEQUENCE;
sequence TEST.TST_TABLE$IDENTITY_SEQUENCE doesn't exist