SQL - Two foreign keys that have a dependency between them
Posted
by Brian
on Stack Overflow
See other posts from Stack Overflow
or by Brian
Published on 2010-06-02T17:20:37Z
Indexed on
2010/06/02
17:23 UTC
Read the original article
Hit count: 290
The current structure is as follows:
Table RowType: RowTypeID Table RowSubType: RowSubTypeID FK_RowTypeID
Table ColumnDef: FK_RowTypeID FK_RowSubTypeID (nullable)
In short, I'm mapping column definitions to rows. In some cases, those rows have subtype(s), which will have column definitions specific to them. Alternatively, I could hang those column definitions that are specific to subtypes off their own table, or I could combine the data in RowType and RowSubType into one table and work with a single ID, but I'm not sure either is a better solution (if anything, I'd lean towards the latter, as we mostly end up pulling ColumnDefs for a given RowType/RowSubType).
Is the current design SQL Blasphemy?
If I keep the current structuree, how do I maintain that if RowSubTypeID is specified in ColumnDef, that it must correspond to the RowType specified by RowTypeID? Should I try to enforce this with a trigger or am I missing a simple redesign that would solve the problem?
© Stack Overflow or respective owner