[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 756
  • Last Modified:

How to add a Foreign Key to an existing table?

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?
0
FairyBusiness
Asked:
FairyBusiness
1 Solution
 
NetExpert_plCommented:
ALTER TABLE `necklaces_metals` ADD CONSTRAINT `necklaces_fk` FOREIGN KEY (`Product_Id`) REFERENCES `necklaces` (`Id`);
0
 
FairyBusinessAuthor Commented:
thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now