public inbox for [email protected]
help / color / mirror / Atom feedFrom: Andre Schnabel <[email protected]>
To: Steve SAUTETNER <[email protected]>
To: [email protected]
Subject: Re: concurent updates
Date: Thu, 26 Jul 2001 18:26:27 +0200
Message-ID: <[email protected]> (raw)
References: <[email protected]>
Hi,
if you define the foreign key with "ON UPDATE CASCADE" you don't have to
worry about updating table2.
Would look like this:
the tables:
create table table1 (id int primary key, col1 int);
create table table2 (id int primary key references table1(id) ON UPDATE
CASCADE, col2 int);
the (one and only) UPDATE:
update table1 set id = 1001 where id = 1;
Your 2nd UPDATE will be done automatically.
The other solution for your problem is less elegant.
First INSERT a new record ( 1001 , x) for each row (1, x) in table1 into
table1
then UPDATE table2
last DELETE all records (1, x) from table1
Would look like:
BEGIN;
INSERT INTO table1 SELECT 1001, col1 FROM table1 WHERE id=1;
UPDATE table2 set id = 1001 WHERE id = 1;
DELETE FROM table1 where id=1;
COMMIT;
Hope this would help,
Andre
----- Original Message -----
From: Steve SAUTETNER
To: [email protected]
Sent: Thursday, July 26, 2001 11:19 AM
Subject: [GENERAL] concurent updates
hi everybody !
I've got a little problem when updating a primary key in two table
where the primary key of the one is a foreign key from the second :
here are the 2 tables :
create table table1 (id int primary key, col1 int);
create table table2 (id int primary key references table1(id), col2 int);
and the 2 updates :
1) update table2 set id = 1001 where id = 1;
2) update table1 set id = 1001 where id = 1;
i can't execute them separately because of an integrity constraint
violation.
i've got the same error in a BEGIN / COMMIT block containing the updates.
Does any one see how two help me ?
thanks.
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to [email protected])
view thread (12+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: concurent updates
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox