总参与约束PostgreSQL

时间:2017-10-26 08:54:06

标签: database postgresql database-design constraints relational-database

我正在寻找一种在postgreSQL中编写总参与约束的方法。

我有这种具有其他属性和关系的ER图:

|推出| ==== ----- |国家|

我已经写了下面的三个表格,但我怎样才能获得"至少一个"由release和release_country之间的粗线表示的约束。

CREATE   TABLE   country( id   integer   PRIMARY   KEY, name   text   NOT   NULL);

CREATE TABLE release(
    id   integer   PRIMARY   KEY,
    title   text   NOT   NULL,
    status   integer,
    barcode   numeric(26,0),
    packaging   CHAR(22),
    FOREIGN   KEY(status)   REFERENCES   release_status
);

CREATE   TABLE   release_country(
    release   integer, 
    country   integer,
    day   integer,CHECK   (day   >=   0   AND   day   <=   31), 
    month   integer,CHECK   (month   >=   0   AND   month   <=   12), 
    year   integer,
    PRIMARY   KEY(release,country),
    FOREIGN   KEY(release)   REFERENCES   release, 
    FOREIGN   KEY(country)   REFERENCES   country
);

0 个答案:

没有答案