In my project I have an object Player
(attr example: pl_id
, pl_data1
) that is one of these types:
- Its
GoalKeeper
(attr example:gk_data1
) - OR
Defender
(attr example:df_data1
) - OR
Forward
(attr example:fw_data1
)
In mapping this objects to database :
Option 1:
Make a Table Player
with columns (pl_id
,pl_data1
,gk_data1
,df_data1
,fw_data1
)
In this option we have one record for any player. So if an player is a goalkeeper, the column gk_data1
will be filled and other column (df_data1
and fw_data1
) will be null.
Option 2: make
- Table
Player
with columns: (pl_id
,pl_data1
,type
) - Table
GoalKeeper
with columns: (pl_id
,gk_data1
) - Table
Defender
with columns: (pl_id
,df_data1
) - Table
Forward
with columns: (pl_id
,fw_data1
)
and pl_id
in child tables (GoalKeeper
,Defender
and Forward
) links to Player.pl_id
. relation from child tables to parent is one to one and from parent to childs is one to one_or_zero.
questions:
- which is better?
- is there any other (and better) options?
- and finally what is best practice in this situation?