How to Connect Your Tables with Foreign Keys in phpMyAdmin
- First, create more than 1 table to connect
2. Select one of them, then go to the Structure tab, and select the Relation view button.
3. Fill in the details
- Fill in the Constraint name
This constraint name helps you easily identify and manage your database's constraints.
Ex: “fk_notes_users” - Select ON DELETE & ON UPDATE
These clauses define what actions should be taken when a referenced row in the parent table is deleted or updated.
CASCADE: When the parent row is deleted/changed, the child rows are also automatically deleted/changed.
SET NULL: The foreign key values in the child rows are set to NULL when the parent row is deleted/changed.
NO ACTION: The database system prevents the deletion/update of the parent row if associated child rows exist.
Get Andrew Surya’s stories in your inbox
Join Medium for free to get updates from this writer.
RESTRICT: Similar to NO ACTION, prevents deletion/update if associated child rows exist.
I recommend ON DELETE clauses to prevent unintended actions
- Select a column from the selected table to establish a connection with another table using foreign keys
- Adjust Database, Table, and Column values based on your connection.
Here, I connect my “users” table with the “remember_notes” tables using user_id as the foreign key.
This view is available in [your_database] page -> More tab -> Designer
You can also create the connection from the Designer View.
I hope it helps!
References:
- [Youtube Video]How to create a foreign key in phpMyAdmin
- [Webpage]MySQL official website
I just found out about this today and want to save it and share it with more people!~








