Postgres的外键深入使用(三)

2014-11-24 10:48:08 · 作者: · 浏览: 2
=# insert into t_c values(1,2);
INSERT 0 1
postgres=# insert into t_c values(null,null);
INSERT 0 1
postgres=# insert into t_c values(1,null);
ERROR: insert or update on table "t_c" violates foreign key constraint "fk_c"
DETAIL: MATCH FULL does not allow mixing of null and nonnull key values.
--另外一种模式
postgres=# alter table t_c drop constraint fk_c;
ALTER TABLE
postgres=# alter table t_c add constraint fk_c foreign key(id1,id2) references t_p(id1,id2) match simple;
ALTER TABLE
postgres=# insert into t_c values(1,2);
INSERT 0 1
postgres=# insert into t_c values(1,null);
INSERT 0 1
postgres=# insert into t_c values(null,null);
INSERT 0 1 可以看到插空值入有明显的区别。