DROP SEQUENCE

删除序列的 SQL 命令

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

DROP SEQUENCE 添加于 PostgreSQL 6.4

更改历史记录

示例

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 命令

另请参阅

创建序列修改序列

反馈

提交任何关于 "DROP SEQUENCE" 的评论、建议或更正 此处