문제

I have a schema on my db where there are some tables. I have to create a table into this schema and i have to connect it with the others already present on the schema.I make an example:

Tables already present:

SCHOOL(IdSchool,NumStud,IdCountry);
SHOP(IdShop,IdCountry);

New table:

Country(IdCountry,....);

I want to know if there is an automatic mode to connect them (it means not to set the foreign key manually).

도움이 되었습니까?

해결책

I want to know if there is an automatic mode to connect them (it means not to set the foreign key manually).

No.

How is the DBMS to know that Country.IdCountry and SCHOOL.IdCountry are given the same name with the intention to be connected, instead of just accidentally?

You'll have to use ALTER TABLE ... ADD FOREIGN KEY (...) REFERENCES ...1 to explicitly create the foreign key in the existing table.


1 Or ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY (...) REFERENCES ....

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top