Drop sequence and cascade

前端 未结 4 1441
粉色の甜心
粉色の甜心 2021-02-05 05:43

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:



        
4条回答
  •  死守一世寂寞
    2021-02-05 06:34

    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;
    

    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;
    

    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;
    

提交回复
热议问题