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