Subject | Re: [firebird-support] Walk me thru setting up Ref. Integrity please |
---|---|
Author | Don Gollahon |
Post date | 2004-07-18T00:05:14Z |
""Florian Hector"" <FHector@...> wrote in message
news:<002101c46c1b$819db650$027ba8c0@minitower>...
data in them. Is there a problem with adding RI to tables with existing
data?
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
news:<002101c46c1b$819db650$027ba8c0@minitower>...
> Don,The tables aready exist and have been in use for a year so have plenty of
>
> 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
> );
>
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:My Attendance table has a 2-field primary key: AttDate and PersonID.
>
> 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:This is almost exactly what my 2nd post has. But it didn't work. Is it
>
> Alter Table Attendance add Constraint FK_Persons FOREIGN KEY
> (PersonID) REFERENCES Persons (PersonID) ON UPDATE CASCADE ON DELETE
> CASCADE;
>
>
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