删除顺序和级联 [英] Drop sequence and cascade

查看:85
本文介绍了删除顺序和级联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用CASCADE在一个语句中删除表中使用的序列和表本身,但是我得到了NOTICE,并且表未删除。例如:

I would like to drop the sequence used in table and the table itself in one statement using CASCADE, but I'm getting NOTICE and table is not dropped. For example:

CREATE SEQUENCE seq1;
CREATE TABLE t1 (f1 INT NOT NULL DEFAULT nextval('seq1'));

然后当我这样做时:

DROP SEQUENCE seq1 CASCADE;

我收到以下消息,但该表未删除:

I get following message, and the table is not dropped:

NOTICE:  drop cascades to default for table t1 column f1

我肯定做错了,但这是我在PostgreSQL中的第一步。

I'm definitely doing something wrong but these are my very first steps in PostgreSQL.

推荐答案

关于依赖的误解。该表从不作为关联序列的从属对象,并且从不丢弃

You have a misconception about dependencies. The table never is a depending object of an associated sequence and is never dropped by a

DROP SEQUENCE ... CASCADE;

仅来自序列的默认值取决于序列,如果序列用 CASCADE 删除。

Only a DEFAULT value drawing from the sequence "depends" on the sequence and is set to NULL if the sequence is deleted with CASCADE.

反之亦然:如果序列归表列所有并使用

It is the other way round: if the sequence is owned by a table column it is dropped with a

DROP TABLE f1 CASCADE;

要使表列拥有一个序列,可以使用 serial 类型,如Milen所建议的那样。或者,您可以更改现有序列

For a sequence to be owned by a table column you can either use the serial type as Milen already suggested. Or you can ALTER an existing sequence:

ALTER SEQUENCE seq1 OWNED BY t1.f1;

这篇关于删除顺序和级联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆