self referenced table ?

Started by BRINER Cedricabout 22 years ago2 messagesgeneral
Jump to latest
#1BRINER Cedric
work@infomaniak.ch

Hi,

how can we do this ?

CREATE TABLE test (key1 int, key2 int , primary key (key1,key2), parent
<?kind of data type?> constraint parent references test );

C�dric BRINER

#2Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: BRINER Cedric (#1)
Re: self referenced table ?

On Fri, 19 Mar 2004, BRINER Cedric wrote:

CREATE TABLE test (key1 int, key2 int , primary key (key1,key2), parent
<?kind of data type?> constraint parent references test );

Foreign keys must reference a unique value. If the only uniqueness
constraint is (key1, key2) as above, then it requires two columns to do
the constraint (one holding the referenced key1 value, one holdign the
referenced key2 value) and a table level foreign key constraint or you
need something like a serial key added to the table.