Board index » delphi » Cascade Updating a Primary Key on Foreign Tables

Cascade Updating a Primary Key on Foreign Tables

Hi,

I have a table Table1 with fields:
  Create Table Table1(
    Cod1 numeric(5) not null,
    Name1 varchar(50),
    Primary Key(Cod1));
Then, Cod1 is a foreign key on:
  Create Table Table2(
    Cod2 numeric(5) not null,
    Name2 varchar(50),
    Cod1 numeric(5) not null,
    Primary Key(Cod2),
    Foreign Key(Cod1));

I would like to update Cod1 on
Table1 and, automatically, update
Cod1 on Table2. Is this possible
on DBMSs like SQL Server 6.5 or
InterBase 5.0 ?

Or I have to disable temporarily
the constraint Foreign Key, update
Table1, update Table2, and enable
the constraint again ?

PS: DBs weaks like Access make this!

  vcard.vcf
< 1K Download
 

Re:Cascade Updating a Primary Key on Foreign Tables


Hi

Quote
>I have a table Table1 with fields:
>  Create Table Table1(
>    Cod1 numeric(5) not null,
>    Name1 varchar(50),
>    Primary Key(Cod1));
>Then, Cod1 is a foreign key on:
>  Create Table Table2(
>    Cod2 numeric(5) not null,
>    Name2 varchar(50),
>    Cod1 numeric(5) not null,
>    Primary Key(Cod2),
>    Foreign Key(Cod1));

>I would like to update Cod1 on
>Table1 and, automatically, update
>Cod1 on Table2. Is this possible
>on DBMSs like SQL Server 6.5 or
>InterBase 5.0 ?

>Or I have to disable temporarily
>the constraint Foreign Key, update
>Table1, update Table2, and enable
>the constraint again ?

>PS: DBs weaks like Access make this!

With InterBase 5.x do:

Create Table Table2(
   Cod2 numeric(5) not null,
   Name2 varchar(50),
   Cod1 numeric(5) not null,
   Primary Key(Cod2),
   Foreign Key(Cod1)  References Table1(Cod1) ON UPDATE CASCADE);

Good luck

Andy

Other Threads