-2

I have an entity that holds two different sub-entities, e.g, a company that holds different trainees and using a trainee entity that holds special attributes, with the identifier being the trainee_id.

The trainee might be either student or an employee in a company. The training program needs to differentiate between the trainees, so i made the student and the employee as two different sub-entities in the trainee entity.

Obviously, the training program will deal with the trainees by their trainee_id, so the trainee_id will be the primary_key for the both sub_entities, and the sub-entities can't have a special identifier (i can't use the student's id as a primary key for the sub_entity).

I want to derive an important non-primary key from the sub-entity with its primary key (trainee_id) to the related entity.

How can i derive a non-primary key as a foreign key to another table?

Alex
  • 1,643
  • 1
  • 14
  • 32
prog_azma
  • 1
  • 6
  • This is what is known as a "run on sentence". Put some effort into punctuation and capitalization. You're not e.e. cummings. This makes your question harder to read and understand. – duffymo Nov 26 '15 at 13:31
  • sorry, english is not my first language. I'll make some effort in improving it.Thanks for that. – prog_azma Nov 26 '15 at 13:33
  • As I understand this, you want a structure for a company which handles many trainees. For each trainee, you need to store data which states whether they are students or not, and which company they are training with. Does that sound about right? If you can explain what you're trying to achieve rather than what structures you have built, it might help people to work out the best answer. From how I understand it, it looks like Bital Shah's answer will do the job, but it would help if you could clarify a little. – Alex Nov 26 '15 at 13:46

1 Answers1

1

You can make a column with unique constraint and try to make that foreign key. Please see here: Foreign Key to non-primary key

Community
  • 1
  • 1
Bilal Shah
  • 1,135
  • 7
  • 17
  • 42