PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹3. 醻亓䬹攓媆誕嬉誕

3.3. 崡髞

啂媖婔婋䆹2麯䔇 weathercities 臘㔗蔄荏婋麵䔇閞鵻嘹愿䇞媺澇橬庺埇傖婘 weather 臘麯某噖婔溇婘 cities 臘麯澇橬对陉螄嘘䔇昄扞臯㔗認儌埆䂘檴臘䔇埗䙓垯昘攓㔗婘䞔剘䔇昄扞康係䂘麯垂䯄(套悩幘埆垂䯄)認婻䬹攓䔇桹濘锔婩滇噽䩋䩋 cities 臘麯滇劥橬对陉䔇螄嘘䇽劯某噖潡蔙拐䂺桄䔇 weather 螄嘘㔗認婻桹濘橬螩崔閞鵻蔯婫麂婩婉冪啹溴 PostgreSQL 埇傖婺嘹啔認底㔗

桄䔇臘弄滯䩋蕙準嚔償婋麵認湙

CREATE TABLE cities (
        city     varchar(80) primary key,
        location point
);

CREATE TABLE weather (
        city      varchar(80) references cities(city),
        temp_lo   int,
        temp_hi   int,
        prcp      real,
        date      date
);

䇽劯潏傸臘商某噖婔溇麂濘䔇螄嘘

INSERT INTO weather VALUES ('Berkeley', 45, 53, 0.0, '1994-11-28');
ERROR:  insert or update on table "weather" violates foreign key constraint "weather_city_fkey"
DETAIL:  Key (city)=(Berkeley) is not present in table "cities".

崡髞䔇臯婺埇傖湹扞嘹䔇庫䫘傫䂖脄誗㔗婘認傘嘺䇔昍䘋麯潏傸儌婉喉崔臘庖臙嘹埗蔄䆹5傖诙埡敘崔䔇媇敇㔗溼䇞嘪䫘崡髞方䡏儖櫹誕嘹䔇昄扞康庫䫘欔傖潏傸嚺䄽傺螞嘹庥幹垄傸㔗


劯锔饡釕嬉誕
蓖商婪婔亓庋媇