例如确保没有人可以在 weather 表里插入一条在 cities 表里没有匹配记录的记录∶ CREATE TABLE cities (
name varchar(80) primary key,
location point
);CREATE TABLE weather (
city varchar(80) references weather,
temp_lo int,
temp_hi int,
prcp real,
date date
);然后试图插入一条非法的记录∶ INSERT INTO weather VALUES ('Berkeley', 45, 53, 0.0, '1994-11-28');ERROR: <unnamed> referential integrity violation - key referenced from weather not found in citiesreference 的就是外键了
name varchar(80) primary key,
location point
);CREATE TABLE weather (
city varchar(80) references weather,
temp_lo int,
temp_hi int,
prcp real,
date date
);然后试图插入一条非法的记录∶ INSERT INTO weather VALUES ('Berkeley', 45, 53, 0.0, '1994-11-28');ERROR: <unnamed> referential integrity violation - key referenced from weather not found in citiesreference 的就是外键了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货