community.borland.com

Article #25347: An example of foreign key referencing self table

Problem:
Customer wants to perform the following constraint on the table and 
can't find an example to do so.   

Tablec is containing field1 and field2.  Need the constraint to ensure 
that the value in field2 is contained in field1. 

Solution:
This can be done using a self table references.

Something like this:

create table tablec (field1 char(5) not null primary key,
field2 char(5),
foreign key  (field2) references tablec (field1));

OR

create table tablec (field1 char(5) not null primary key,
field2 char(5),
constraint const_name 
foreign key  (field2) references tablec (field1));

Last Modified: 18-OCT-00