Creating and editing foreign keys on MySQL and MariaDB servers
This module a part of the host administration
This module displays all foreign keys installed on the connected server.
New foreign keys for existing databases can be created here
Create a new foreign key on the server
Edit the foreign key
Deleting foreign key from the server
Foreign keys are constraints in MySQL and MariaDB that ensure referential integrity between two tables. You create a relationship between two tables based on the values of the columns in those tables.
When a foreign key is defined in one table, it references the primary key of another table. This is called the parent table. The table containing the foreign key is called the subtable. The foreign key ensures that the values in the child table columns always match those in the parent table columns.
MySQL and MariaDB support two types of foreign keys: ON DELETE and ON UPDATE . These specify the action to take when a record in the parent table is deleted or updated.
Available actions are:
CASCADE: When a row in the parent table is deleted or updated, deletes or updates the corresponding rows in the child table. RESTRICT: Prevents deleting or updating a row in the parent table if there are corresponding rows in the child table. SET NULL: Sets the value of the foreign key column in the child table to NULL when a row in the parent table is deleted or updated. NO ACTION: Similar to RESTRICT but generates a warning instead of an error if there are matching rows in the child table.
Foreign keys are an important feature of relational databases as they help ensure data consistency and prevent orphan records in the sub-table.