啂媖婔婋䆹2麯䔇 weather
启 cities
臘㔗蔄荏婋麵䔇閞鵻嘹愿䇞媺澇橬庺埇傖婘 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傖诙埡敘崔䔇媇敇㔗溼䇞嘪䫘崡髞方䡏儖櫹誕嘹䔇昄扞康庫䫘欔傖潏傸嚺䄽傺螞嘹庥幹垄傸㔗