Example of how to create a foreign key pointing to a compound primary key

By: Borland Staff

Abstract: Example for InterBase 4.x and later

Problem:
There is no example of how to create a foreign key that points to a primary
key with multiple fields.


Solution:
IB V4.x
IB V5.x

Here is an example of how to do this operation:

create database "a.gdb" user "sysdba" password "masterkey";
create table table1 (f1 char(5) not null, f2 char(5) not null,
   primary key (f1,f2));
create table table2 (c1 char(5) not null, c2 char(5) not null,
   c3 char(5) not null,
   primary key (c1),
   foreign key (c2,c3) references table1 (f1,f2));

Server Response from: ETNASC03