سؤال

Im learning about databases, I would like to know that is it possible to have a column in a table which gets its Foreign key from another table and at the same time has a primary key?

For example:

X: class, teacher

Y:class(FK,PK)?,teacher

هل كانت مفيدة؟

المحلول

Yes, it is.

This is often used to represent a 1-1 relationship, or many-to-many relationships when there is a composite primary key across columns which are all foreign keys

The most common place I have seen it is in relationships created by ORMs to represent inheritance.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top