For instance, if you remove the person with id 1, the employee profiles that reference this id will also be needed to remove, so, in this case, we will apply with the DELETE statement the MySQL ON DELETE CASCADE for a foreign key.Again, assume that when you cancel a row in the person table, you also desire to remove the rows from the employee table associated with the Primary key record in the person table. ![]() Hence, we can conclude that the relation between the person and employee tables is distinct to various, i.e.An employee profile will not existent lacking a person. However, every employee profile belongs to just one person in the table relation. In the MySQL database structure model, each person occupies single or multiple employee profiles. Supposing we have created two MySQL tables, the person(ID, Name, Address) and Employee(EmpID, ID, Profile, Contact).The parent table in MySQL contains the original key values, while the child table is a linked table that refers to the main key values in the parent table within the database.How does ON DELETE CASCADE work in MySQL? This means that the child data will be altered accordingly. CASCADE: When you use ON DELETE or ON UPDATE in aggregation, any changes made to the parent data will also affect the child data.ON DELETE CASCADE: This MySQL Keyword is responsible for changing the child table when the parent table is affected.Col1_Parent,….,ColN_Parent: These are the parent table columns that hold Primary keys to which the foreign key will be associated.ParentTable_Name: In the query statement, you should use the name of the parent table whose primary keys are linked to the child table.Col1_Child,…,ColN_Child: These are the child table’s columns with reference to the Primary key in the parental table.It has a default value of NULL when we do not provide any data type, but we need to add some data type for the proper execution of the query, either NULL or NOT NULL. Col1.,ColN: We want to create these column names with the respective data type in the table.ChildTable_Name: It denotes the name of the child table related to the parent table. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |