Subject Re: [firebird-support] Walk me thru setting up Ref. Integrity please
Author Florian Hector
Don,

> The basics of my 2 tables are:
>
> Master Table name: People
> Primary key: PersonID
>
> Detail Table: Attendance
> Primary Key: AttDate, PersonID

In a script you would first create your two tables:

Create Table Persons (
PersonID Integer not null,
PersonName VarChar(30)
);

Create Table Attendance (
AttID Integer not null,
PersonID Integer not null,
AttDate Date
);

After that you would create the primary keys for both tables:

Alter Table Persons add constraint PK_Persons Primary Key (PersonID);
Alter Table Attendance add constraint PK_Attendance Primary Key (AttID);

After that you would create the RI keys for the second table:

Alter Table Attendance add Constraint FK_Persons FOREIGN KEY (PersonID)
REFERENCES Persons (PersonID) ON UPDATE CASCADE ON DELETE CASCADE;


Florian