I am working on a scenario like this : I have an employee table which has columns like this


Also I have a Joining_Vital table


How can I link this two tables ? As I guess it would be a many-to-one relationship(as one joining_vital can contain many employees) from Employee table to Joining_Vital table

I cannot establish the foreign key on the Employee_ID column of the Employee table. I am naive to Database thing Could you guys please help me out how to do it? I cannot figure out the scenario Please explain me out. Am I missing anything here?

  • "I cannot establish the foreign key on the Employee_ID column of the Employee table" - why? What error do you get? What have you tried that did not work?
    – user1822
    Aug 26, 2014 at 6:14
  • I guess when I try to make the same column as PK and FK also MySQL not allowing me to do so
    – recmach
    Aug 26, 2014 at 6:15
  • Please share the commands you execute
    – Antonios
    Aug 26, 2014 at 7:53

1 Answer 1


Hi and welcome to the forums. A simple Google led me here.

  Employee_ID INT,
  First_name VARCHAR(25),
  Last_name VARCHAR(25),
  PRIMARY KEY (Employee_ID),  -- Must be present - otherwise you cannot create the FOREIGN KEY
  Employee_designation VARCHAR(10)

CREATE TABLE joining_vital
  Employee_ID INT(10),
  Joining_ID INT(10),
  Joining_date DATE,
  FOREIGN KEY (Employee_ID) REFERENCES employee (Employee_ID)

Take a look here and also here - help us to help you! These forums are a great resource and you will get more out of them if you take the trouble to follow the guidelines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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