How to add a Foreign Key to an existing table?

Posted on 2012-08-25
Last Modified: 2012-08-26
Hi, I am trying to add a Foreign Key to an existing table with a column that already exists as well like so:

ALTER TABLE necklaces_metals ADD Foreign Key (Product_Id) references necklaces (Id)

Open in new window

But I keep getting an syntax error.  Anyone know the correct way to do this?
Question by:FairyBusiness
    LVL 4

    Accepted Solution

    ALTER TABLE `necklaces_metals` ADD CONSTRAINT `necklaces_fk` FOREIGN KEY (`Product_Id`) REFERENCES `necklaces` (`Id`);

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi ( had suggested a “sed” way, I actually shell …
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now