pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedMechanics of UpDate:Cascade
4+ messages / 4 participants
[nested] [flat]
* Mechanics of UpDate:Cascade
@ 2004-01-31 10:45 beyaNet Consultancy <beyanet@ntlworld.com>
0 siblings, 0 replies; 4+ messages in thread
From: beyaNet Consultancy @ 2004-01-31 10:45 UTC (permalink / raw)
To: pgsql-sql
Hi,
could someone please explain to me the mechanics of an UpDate:Cascade?
Delete:Cascade I fully understand but not Update. I have 2 tables A and
B. On B I have created a foreign key on user_id in both B and A for
Update and Delete cascade. If I delete from A it deletes all from B. If
I update A what happens in B?
regards
Andrew
^ permalink raw reply [nested|flat] 4+ messages in thread
* Mechanics of Update:Cascade
@ 2004-01-31 10:50 beyaRecords - The home Urban music <uzo@beya-records.com>
0 siblings, 2 replies; 4+ messages in thread
From: beyaRecords - The home Urban music @ 2004-01-31 10:50 UTC (permalink / raw)
To: pgsql-sql
Hi,
could someone please explain to me the mechanics of an UpDate:Cascade?
Delete:Cascade I fully understand but not Update. I have 2 tables A and
B. On B I have created a foreign key on user_id in both B and A for
Update and Delete cascade. If I delete from A it deletes all from B. If
I update A what happens in B?
many thanks
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Mechanics of Update:Cascade
@ 2004-01-31 15:26 Stephan Szabo <sszabo@megazone.bigpanda.com>
parent: beyaRecords - The home Urban music <uzo@beya-records.com>
1 sibling, 0 replies; 4+ messages in thread
From: Stephan Szabo @ 2004-01-31 15:26 UTC (permalink / raw)
To: beyaRecords - The home Urban music <uzo@beya-records.com>; +Cc: pgsql-sql
On Sat, 31 Jan 2004, beyaRecords - The home Urban music wrote:
> Hi,
> could someone please explain to me the mechanics of an UpDate:Cascade?
> Delete:Cascade I fully understand but not Update. I have 2 tables A and
> B. On B I have created a foreign key on user_id in both B and A for
> Update and Delete cascade. If I delete from A it deletes all from B. If
> I update A what happens in B?
Basically it means that if you update the referenced key in A, the
associated referencing values in B changes as well so as to attempt to
keep the associations the same.
Here's an example:
sszabo=# create table a(a int primary key, b int);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "a_pkey"
for table "a"
CREATE TABLE
sszabo=# create table b(a_key int references a on update cascade, b int);
CREATE TABLE
sszabo=# insert into a values (3, 4);
INSERT 535937 1
sszabo=# insert into a values (4, 5);
INSERT 535938 1
sszabo=# insert into b values (3,104);
INSERT 535939 1
sszabo=# insert into b values (4,105);
INSERT 535940 1
sszabo=# select * from a;
a | b
---+---
3 | 4
4 | 5
(2 rows)
sszabo=# select * from b;
a_key | b
-------+-----
3 | 104
4 | 105
(2 rows)
sszabo=# update a set a=a+100;
UPDATE 2
sszabo=# select * from a;
a | b
-----+---
103 | 4
104 | 5
(2 rows)
sszabo=# select * from b;
a_key | b
-------+-----
103 | 104
104 | 105
(2 rows)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Mechanics of Update:Cascade
@ 2004-01-31 17:42 Richard Huxton <dev@archonet.com>
parent: beyaRecords - The home Urban music <uzo@beya-records.com>
1 sibling, 0 replies; 4+ messages in thread
From: Richard Huxton @ 2004-01-31 17:42 UTC (permalink / raw)
To: beyaRecords - The home Urban music <uzo@beya-records.com>; pgsql-sql
On Saturday 31 January 2004 10:50, beyaRecords - The home Urban music wrote:
> Hi,
> could someone please explain to me the mechanics of an UpDate:Cascade?
> Delete:Cascade I fully understand but not Update. I have 2 tables A and
> B. On B I have created a foreign key on user_id in both B and A for
> Update and Delete cascade. If I delete from A it deletes all from B. If
> I update A what happens in B?
The column should be changed there too. For example, if we have
B.user_id => A.user_id and change A.user_id from 100 to 200 then the same
should happen in B too.
--
Richard Huxton
Archonet Ltd
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2004-01-31 17:42 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-31 10:45 Mechanics of UpDate:Cascade beyaNet Consultancy <beyanet@ntlworld.com>
2004-01-31 10:50 Mechanics of Update:Cascade beyaRecords - The home Urban music <uzo@beya-records.com>
2004-01-31 15:26 ` Re: Mechanics of Update:Cascade Stephan Szabo <sszabo@megazone.bigpanda.com>
2004-01-31 17:42 ` Re: Mechanics of Update:Cascade Richard Huxton <dev@archonet.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox