DROP SEQUENCE

用于删除序列的 SQL 命令

DROP SEQUENCE 是用于删除序列的 DDL 命令。

DROP SEQUENCEPostgreSQL 6.1 中添加。

变更历史

示例

DROP SEQUENCE 的基本用法示例

postgres=# DROP SEQUENCE foo_id_seq;
DROP SEQUENCE

删除可能不存在的序列

postgres=# DROP SEQUENCE IF EXISTS foo_id_seq;
NOTICE:  sequence "foo_id_seq" does not exist, skipping
DROP SEQUENCE

尝试删除与表列关联的序列

postgres=# CREATE TABLE bar (id SERIAL);
CREATE TABLE

postgres=# \d bar
                            Table "public.bar"
 Column |  Type   | Collation | Nullable |             Default             
--------+---------+-----------+----------+---------------------------------
 id     | integer |           | not null | nextval('bar_id_seq'::regclass)

postgres=# DROP SEQUENCE bar_id_seq;
ERROR:  cannot drop sequence bar_id_seq because other objects depend on it
DETAIL:  default value for column id of table bar depends on sequence bar_id_seq
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

强制删除序列及其依赖项

postgres=# DROP SEQUENCE bar_id_seq CASCADE;
NOTICE:  drop cascades to default value for column id of table bar
DROP SEQUENCE

postgres=# \d bar
                Table "public.bar"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 id     | integer |           | not null | 

分类

DDL, 序列, SQL 命令

另请参阅

CREATE SEQUENCE, ALTER SEQUENCE

反馈

DROP SEQUENCE” 的任何评论、建议或更正请 在此 提交。