I’ve got one table containing some sort of items, and two tables (a and b) to which these items belong to.
One item refers to either one row in a or one row in b. One a or b can have multiple items.
Is there a better design than the following (using Oracle 10)?
Any pitfalls to watch out for?
id a_id(fk) b_id(fk)
1 1 NULL
2 1 NULL
3 NULL 1
4 2 NULL
That’s a pretty good design on a number of counts:
The only snag is that this database structure by itself doesn’t check that an item is linked to only one of A or B (and not both). Check constraints on the Items table will do this job.
Pseudo-code example: