Subject Re: [firebird-support] Walk me thru setting up Ref. Integrity please
Author Don Gollahon
""Florian Hector"" <FHector@...> wrote in message
news:<002101c46c1b$819db650$027ba8c0@minitower>...
> Don,
>
> 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
> );
>

The tables aready exist and have been in use for a year so have plenty of
data in them. Is there a problem with adding RI to tables with existing
data?

> 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);
>

My Attendance table has a 2-field primary key: AttDate and PersonID.

> 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;
>
>

This is almost exactly what my 2nd post has. But it didn't work. Is it
because data already exists in the table? If so then what do I have to do
to add RI to existing tables? Delete my customer's data to get the tables
right?

Thanks.

Don