Re: About referential integrity.

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: BOURIAUD <david(dot)bouriaud(at)ac-rouen(dot)fr>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: About referential integrity.
Date: 2002-02-25 17:46:47
Message-ID: 1014659208.13241.6853.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, 2002-02-25 at 15:01, BOURIAUD wrote:
> Since I fear I'm not clear in the above, let me show you an example.
>
>
> Let's say I create two tables as shown below :
>
> create table t1
> (
> key1 serial PRIMARY KEY,
> field1 varchar(30)
> );
>
> create table t2
> (
> key2 serial not null PRIMARY KEY,
> key1 int4 references t1,
> field2 varchar(30)
> );
>
> As far as I know, t2 and t1 are linked together. If I want to select rows
> that belong to both tables, I would have to write something like this :
> select * from t1, t2 where t1.key1 = t2.key1;
>
> I think this is quite redundant, since I've created my tables so as to make
> sure that they would respect what is in the select above !!!!
>
>
> So, why souldn't I be abble to write :
> select * from t1, t2;
>
> and have the backend returns me only the rows that have t1.key1 = t2.key2 ???

That is not what SQL does.

The purpose of referential integerity is to ensure that a value in one
table corresponds to a row in another. It operates on database changes;
it does not extend to select queries.
--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C

"Peace I leave with you, my peace I give unto you; not
as the world giveth, give I unto you. Let not your
heart be troubled, neither let it be afraid."
John 14:27

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jan Wieck 2002-02-25 19:09:28 Re: PLPGSQL func. defn. for returning resultset?
Previous Message Josh Berkus 2002-02-25 17:21:38 Re: About referential integrity.