Jacky Luk wrote:when you say to have several columns, you mean to have two ids, one for maintainence, one for complaints?
Yes. The foreign key constrain doesn't allow to declare a column that would refer to the union of two tables (this is what you would need with just a single column).
The log table should have two columns, say,
maintenance_id and
complaint_id, that will be declared with the foreign key constraint referring to the appropriate table, with the
CASCADE DELETE option. However, these columns must not be declared
NOT NULL, since only one of these columns will contain a non-null value, depending on the type of the parent record. You shouldn't need more than this.
(Note: please don't quote entire posts. Quote is useful if you want to highlight just some part of the post, or when referring to an older post, which wouldn't otherwise be apparent. Quoting unnecessarily increases clutter and makes the threads less comprehensible. Thanks.)