I have a table (X) with 10 columns, 6 of which are nullable foreign keys (bigint data type) and in every row 5 of them will be NULL.
SOLUTION: Divide table (X) into 2 tables: (X) and (XType) so that (X) includes a big int column (not foreign key) for insert one of six ID and a XType_id column for determining types of 6 data.
Is this solution optimal or the first table with 10 columns is better?
I prefer your first option.
When you have those 6 individual foreign key columns, then you can enforce referential integrity by having actual foreign key constraints to those 6 referenced tables.
If you have a super-smart approach with a single ID and an ID_Type, you cannot enforce referential integrity anymore.
The benefit of being able to truly enforce referential integrity for me far outweighs the "benefit" of having just a single ID column; having a few columns with NULL values isn't bad
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With