Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have an Employee table , and another table named Student. Now I have a third table named the Login. Employee has emp_id as PK , and other specific attributes for an employee. Student has std_id as PK , and other specific attributes for a student.

The login table has user_id as PK , but the user_id should also be FK from both employee and student. Means that if there is a profile for an Employee or Student then there will be a record for them in the login table. But I am not able to link the user_id of the Login table to both Employee and Student at the same time in a one-to-one relationship.

Could you please help me how to that. I am using MySQL for this.

share|improve this question

1 Answer 1

A Login maybe a Student or an Employee.

It sounds like you trying to define a FK relationship from Login to both Student and Employee, this is not correct. You should be defining a FK relationship from Student to Login and Employee to Login

Edit for clarification:

If the PK emp_id for Employee and PK std_id for Student are the FK field then there can only be 1 for each given Login (user_id value).

share|improve this answer
    
That way a login would be related to many students and many employees. I think he wants the opposite. –  ypercube Feb 16 at 22:57
    
No not necessarily. If the PK emp_id for Employee and PK std_id for Student are the FK field then there can only be 1 for each given Login (user_id value). –  Zack Feb 16 at 23:01
    
Well, state that in your answer! –  ypercube Feb 16 at 23:09
    
I thought that it was implicit in the question. However as you suggested I have explicitly stated it in the answer. –  Zack Feb 16 at 23:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.