How would I design this table in SQL?
Posted
by
RSharma
on Stack Overflow
See other posts from Stack Overflow
or by RSharma
Published on 2011-01-10T23:04:13Z
Indexed on
2011/01/12
5:53 UTC
Read the original article
Hit count: 243
I have a parent master table that is generic enough to hold the common information of the children. Since the children were substantially different, we created separate tables for them. So I have something like this:
tblMaster
--------
MasterID int
Name varchar(50) --Common to all children and there are a bunch of fields like this
ChildType int -- Type of Child either ChildOne or ChildTwo
ChildID int -- need to store ChildOneID or ChildTwoID depending on type of Child, so that i can refer to children
tblChild1
--------
ChildOneID int IDENTITY
tblChild2
---------
ChildTwoID int IDENTITY
Should I have a ChildID
in the master that is either ChildOneID
or ChildTwoID
based on the ChildType
column? I have a number of children and I have simplified it for this question.
The other way is to add ChildOneID
and ChildTwoID
as columns in the master, but since i have a number of columns, I will have a lot of null columns
EDIT: Any help is appreciated
© Stack Overflow or respective owner