Search code examples
mysqlstored-procedurescascading-deletes

Delete data in Mysql data base table


  1. How can I delete data form a table with out delete other table data?

  2. Is that possible Null value for foreign key in MySql data base table?

I want to delete one Department without delete other tables data like (shifts, remote_login_id, skills). This my data base ERD. How will I do this?

enter image description here


Solution

  • When you define the foreign key you can choose between SET NULL and CASCADE.

    CASCADE deletes all records that holds reference to the deleted row.

    SET NULL set's the foreign key column to null wherever it referenced the deleted record. For this to work you need to make sure that that column allows null or it won't work.

    http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html