4

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)...?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
JDelage
  • 13,036
  • 23
  • 78
  • 112

2 Answers2

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:

  1. Make sure you've assigned an index to the column you'll be assigning a foreign key to.
  2. Click on "Relation view" under the table details on the "Structure" tab.
  3. Assign your foreign key constraint and decide on the actions for DELETE and UPDATE.
clexmond
  • 1,509
  • 13
  • 20
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