Subject | Conceptual question (about design) |
---|---|
Author | Sergio H. Gonzalez |
Post date | 2011-05-06T14:09:24Z |
Hello there! I use Firebird 2.1, but this question is not specific to
FB, I think
Basically, I have a table with a field which can "point" to two tables
(one or other, but *never* to both)
What the experts says about this scenario?
Option 1) is better to have a field which represent at what table I'm
pointing and then the ID field... ?
Option 2) or just two ID fields (FK to each table) and just leave null
the field I not use...
I hope I'm clear with my question!!
here it is a simple case (not a real one) of what I'm asking.
PURCHASE_INVOICES
==============
ID INTEGER,
DESCRPTION VARCHAR(100)
--
STOCK_MOVEMENTS
=============
ID INTEGER,
DESCRPTION VARCHAR(100)
--
Option 1)
ARTICLES
======
ID INTEGER,
DESCRPTION VARCHAR(100),
LAST_IN_TABLE CHAR(1)
LAST_IN_ID INTEGER
Option 2)
ARTICLES
======
ID INTEGER,
DESCRPTION VARCHAR(100),
ID_PURCHASE_INVOICES INTEGER (FK TO TABLE PURCHASE_INVOICES)
ID_STOCK_MOVEMENTS INTEGER (FK TO TABLE STOCK_MOVEMENTS)
[Non-text portions of this message have been removed]
FB, I think
Basically, I have a table with a field which can "point" to two tables
(one or other, but *never* to both)
What the experts says about this scenario?
Option 1) is better to have a field which represent at what table I'm
pointing and then the ID field... ?
Option 2) or just two ID fields (FK to each table) and just leave null
the field I not use...
I hope I'm clear with my question!!
here it is a simple case (not a real one) of what I'm asking.
PURCHASE_INVOICES
==============
ID INTEGER,
DESCRPTION VARCHAR(100)
--
STOCK_MOVEMENTS
=============
ID INTEGER,
DESCRPTION VARCHAR(100)
--
Option 1)
ARTICLES
======
ID INTEGER,
DESCRPTION VARCHAR(100),
LAST_IN_TABLE CHAR(1)
LAST_IN_ID INTEGER
Option 2)
ARTICLES
======
ID INTEGER,
DESCRPTION VARCHAR(100),
ID_PURCHASE_INVOICES INTEGER (FK TO TABLE PURCHASE_INVOICES)
ID_STOCK_MOVEMENTS INTEGER (FK TO TABLE STOCK_MOVEMENTS)
[Non-text portions of this message have been removed]