changing value of a primary key in a table and FK in referenced tables
I wish to change the primary key of a table, and also change the foreign key of the tables that reference it.
for example table employee has PK idEmployee = 1 table payroll has FK idEmployee = 1
I want to update employee to idEmployee = 2 and let the table payroll chang开发者_如何学JAVAe FK idEmployee automatically.
is this posible in mysql?
thanks.
Yes - you have to first set the ON UPDATE clause in the foreign key constraint:
CASCADE: Delete or update the row from the parent table and automatically delete or update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported. Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column in the parent table or in the child table.
精彩评论