I am totally new to php and mysql. I have already one table in mysql .now i want to add foreign key. how to alter table and add foreign key using phphmyadmin?
The form to put up the fk is under: table -> structure -> relationship overview
you need to setup index keys for the foreign keys
sorry this is in german but is the same position of link in other languages
You can do it by following steps
Change the storage engine of table to Inodb by going to operations section >> Table options >> Storage Engine >> Inodb.
Go to table structure >> Below the structure click on Relation view.
Now in the primary key column change the column which will be related to this table.
Select On Delete and On Update dropdown fields as per requirement.
Wolla you are done
you can easily google it.
ALTER TABLE yourtable
ADD CONSTRAINT fkey
FOREIGN KEY (P_Idq)
REFERENCES Personstable(P_Idq)
through phpmyadmin
If you want to use phpMyAdmin to set up relations you have to do 2 things. First of all you have to define an index on the foreign key column in the referring table ( Then, go to relation view (in the referring table) and select the refereed column and the on update and on delete actions.I think foreign keys are really useful if you have multiple tables linked to one another, in particular your delete scripts will become very short if you set the referencing options correctly. Make sure both of the tables have the InnoDB engine selected.
Also refer: http://www.binarytides.com/create-foreign-key-phpmyadmin/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With