Re: on update restrict

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Mister ics <mister_ics(at)hotmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: on update restrict
Date: 2001-08-14 12:35:55
Message-ID: 200108141235.f7ECZtW01526@jupiter.us.greatbridge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mister ics wrote:
> Hi,
>
> I'm a little confused by the "on update restrict" option in a referential
> integrity constraint. I don't know if i have not understood the meaning of
> this statement or it does not work properly.
> I think that if it is specified ON UPDATE RESTRICT in a foreign key
> costraint, the sql-server should not perform updates on the referenced rows.
> Here an example:
>
> testdb=>create table t1 (
> id int primary key,
> foo int);
> NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 't1_pkey' for
> table 't1'
> CREATE
>
> testdb=>create table t2 (
> id int primary key,
> ref int references t1(id) on update restrict);
> NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 't2_pkey' for
> table 't2'
> NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY
> check(s)
> CREATE
>
> testdb=>insert into t1 values (1,3000);
> INSERT 19116 1
> testdb=>insert into t2 values (1,1);
> INSERT 19117 1
>
> testdb=> update t1 set foo=2900 where id=1;
> UPDATE 1 <--- for me is wrong, we have updated a row referenced by t2
> with ON UPDATE RESTRICT OPTION
>
> What do you think about ?

The behaviour is correct according to the SQL specifications.
RESTRICT (as well as NO ACTION) means, you cannot change the
primary key value of the referenced row. All other values can
be changed of course.

So an attempt to

UPDATE t1 SET id = 2 WHERE id = 1;

is the thing prevented in your above example.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2001-08-14 12:40:05 create function using language SQL
Previous Message Mister ics 2001-08-14 11:33:42 on update restrict