Subject | Re: [firebird-support] Foreign key without an index? |
---|---|
Author | Helen Borrie |
Post date | 2008-11-06T02:36Z |
At 01:07 PM 6/11/2008, you wrote:
alter table Million_Row
add constraint id_exists
CHECK (exists (select 1 from Five_row
where five_row_id = new.five_row_id ))
./heLen
>I could swear that I saw somewhere that with FB 2 you would be able toNo. In this case, you could avoid the index by implementing your own validation using a CHECK constraint on Million_Row, e.g.,
>avoid creating an index on the table the FK is defined on. For
>instance:
>
>
>
>create table Five_Row (
>
> five_row_id bigint not null,
>
> name varchar(20),
>
> primary key (five_row_id));
>
>
>
>create table Million_Row (
>
> million_row_id bigint not null,
>
> five_row_id bigint not null,
>
> name varchr(20),
>
> primary key (million_row_id),
>
> foreign key (five_row_id) references five_row (five_row_id));
>
>
>
>In this case, there will be an index created on Million_Row to support
>the five_row_id FK. However, since there are only five possible
>values, the number of duplicates in this index are going to be
>astronomical. Is there a way to avoid the creation of this index?
alter table Million_Row
add constraint id_exists
CHECK (exists (select 1 from Five_row
where five_row_id = new.five_row_id ))
./heLen