I have a single table ("#detail" in example below) that will have a child relationship to one of three tables (always one table and no others). For example, #detail rows 'aaaa' and 'bbbb' need a column value that relates to #metainfo1,row1 and row 'cccc' needs to be related to #metainfo2.row1 and 'dddd' needs to be related to #metainfo3,row1.
I would rather not create a new column in #detail for every #metainfo table, because I will have to add new #detail columns as new #metainfo tables are added during the lifetime of the database, and every row in #detail will have at least 2 null values (and more null columns as #metainfo grows).
I thought about creating a junction/join table to sit in between #detail and the #metainfo tables, but that just seems to move the excessive null columns and expansion work to another table (and adds additional IO).
Can anyone recommend a way to make this multiple parent relationship work?
Thanks.
create table #detail (detailid int identity(1,1) primary key , detailinfo varchar(4) )
create table #metainfo1 (meta1id int primary key )
create table #metainfo2 (meta2id int primary key)
create table #metainfo3 (meta3id int primary key)
insert into #detail
select 'aaaa' union select 'bbbb' union select 'cccc' union select 'dddd'
insert into #metainfo1
select 1
insert into #metainfo2
select 1
insert into #metainfo3
select 1