MySQL Forums
Forum List  »  InnoDB

Possible constraint creation
Posted by: GARY BARBER
Date: November 20, 2015 11:56AM

Is there a way to add a constraint between tables that would prevent a record from being deleted from table1 if it exists in table2, but table2 does not have to have an entry from table1.

Example: Table1 is sub_department information with an id field. Table2 is a department configuration table. Table2 has dept_id and sub_dept_id. Some configurations are only for the combination dept_id and sub_dept_id so a matching record must exist in the department table and sub-department table for corresponding id's. Since it is possible only the department has configuration information then sub_dept_id would default to zero. (not in the sub-department table). Because of this I can not add a normal constraint that would stop a sub_department from being removed if it is used in the configuration table.

Thoughts? Thanks!

Options: ReplyQuote


Subject
Views
Written By
Posted
Possible constraint creation
1477
November 20, 2015 11:56AM
688
November 20, 2015 12:20PM
797
November 23, 2015 06:20AM
756
November 23, 2015 01:00PM
743
November 23, 2015 07:01AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.