Possible to condense primary key/serial?

前端 未结 4 1161
挽巷
挽巷 2021-01-21 19:56

I have a database where everything is linked with foreign keys, so the Postgres knows exactly how the database is layed out..

Well, Lets say I have Table1 and Table2.

4条回答
  •  天命终不由人
    2021-01-21 20:35

    Look into on update cascade and on delete cascade.

    create table table_1 (
        id integer
            primary key,
        name char(30)
    );
    create table table_2 (
        id integer
            primary key,
        table_1_id integer
            references table_1
            on update cascade
            on delete cascade,
        detail char(30)
    );
    

提交回复
热议问题