Subject | Re: [firebird-support] Walk me thru setting up Ref. Integrity please |
---|---|
Author | Florian Hector |
Post date | 2004-07-17T16:31:25Z |
Don,
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
> The basics of my 2 tables are:In a script you would first create your two tables:
>
> Master Table name: People
> Primary key: PersonID
>
> Detail Table: Attendance
> Primary Key: AttDate, PersonID
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