Jump to content

adding foreign key to existing table


jobs1109

Recommended Posts

Hi everyone,

 

I am trying to add a foreign key (jointable) to an existing table called (Jobs) and I would like it to

reference the id in users table. Also I like to have it auto update when records added and deleted. ENGINE=InnoDB  When I run the following code I get an error message.

 

 

 


ALTER TABLE Jobs ADD FOREIGN KEY
  (jointable) REFERENCES users (id);

 

 

here is the error message

 

 

Error

 

SQL query:

 

ALTERTABLE Jobs ADDFOREIGNKEY ( jointable )REFERENCES users( id )

 

MySQL said:

#1072 - Key column 'jointable' doesn't exist in table

 

 

What am I doing wrong ? please help

 

Link to comment
Share on other sites

Hi when I remove the brackets I get the followin message.

 

 

Here is the code

 


ALTER TABLE Jobs ADD FOREIGN KEY  jointable REFERENCES users (id);


 

 

here is the error message

 

 

Error

 

SQL query:

 

ALTERTABLE Jobs ADDFOREIGNKEY jointable REFERENCES users( id )

 

MySQL said:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REFERENCES users (id)' at line 1

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.