سؤال

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