2

Let's say I have a table T - its every row has a key (assume TID column). Now I have a second table A where for each row I'd like to have a list of values from TID. How could I achive this?

I thought about creating VARRAY of values from T and putting it in A but I somehow feel it's not a right way to go...

alex
  • 10,900
  • 15
  • 70
  • 100

1 Answers1

3

If one row in T can belong to more than one row in A, the normal way is to create a link table:

create table A_TO_T 
    (
    TID foreign key references T(TID), 
    AID foreign key references A(AID),
    primary key (TID, AID)
    );

A link table is also called a junction or cross-reference table.

If one row in T can only belong to one row in A, you can add a foreign key to the T table:

alter table T add
    AID foreign key references A(AID);
Andomar
  • 232,371
  • 49
  • 380
  • 404
  • 1
    huh, I knew how it works and still I didn't think about it. such a simple solution. thanks! – alex May 21 '15 at 13:22