I can't figure how to indicate that a column is a foreign key in WAMPserver. I suppose I could write the MySQL query for that, but I would think that there is also a way to do that using the user interface (PHPMyAdmin)...?
Asked
Active
Viewed 2.7k times
4
-
WAMP server doesn't imply what you're using to manage your MySQL instance. Are you using PHPMyAdmin, command line, etc? – clexmond Apr 06 '12 at 20:52
-
https://www.youtube.com/watch?v=IdQGFZwP7Xc – Fury Mar 18 '13 at 16:26
2 Answers
7
Creating a foreign key constraint relies on your storage engine being set to something that can support it (such as InnoDB). In PHPMyAdmin, you can set this in "Operations" for the table with the "Storage Engine" option. Once that's complete:
- Make sure you've assigned an index to the column you'll be assigning a foreign key to.
- Click on "Relation view" under the table details on the "Structure" tab.
- Assign your foreign key constraint and decide on the actions for DELETE and UPDATE.

clexmond
- 1,509
- 13
- 20
-
Perfect, thanks. I had my table set with MyISAM, but I probably would do better with InnoDB. – JDelage Apr 06 '12 at 21:51
0
you can add a foreign key for the existing table by the following query
ALTER TABLE sample.employee
ADD FOREIGN KEY (dno)
REFERENCES sample.department(dnumber)
here sample. employee is your current table and sample .department is existing table which has the value for your foreign key dno is current table forign key and dnumber is existing table primary key.

Ram
- 115
- 8