Re: Can a field be a primary key as well as a foreign key?

From: Jan Wieck <janwieck(at)yahoo(dot)com>
To: Andrew Snow <andrew(at)modulus(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Can a field be a primary key as well as a foreign key?
Date: 2002-03-12 21:45:29
Message-ID: 200203122145.g2CLjTU31327@saturn.janwieck.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrew Snow wrote:
>
>
> Can anyone see any problem with the following, practice?

No problem at all. With that setup there can never be a
subchild without the matching child, even if the parent
exists. If a child is deleted, it's subchildren follow, no
need to touch the parent. If that's the relationship of the
data, go ahead.

Jan

>
>
> CREATE TABLE parent (
> foo SERIAL PRIMARY KEY
> );
>
> CREATE TABLE child (
> foo INTEGER PRIMARY KEY REFERENCES parent ON DELETE CASCADE,
> bar TEXT
> );
>
> CREATE TABLE subchild (
> foo INTEGER PRIMARY KEY REFERENCES child ON DELETE CASCADE,
> bar2 TEXT
> );
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>

--

#======================================================================#
# 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

Browse pgsql-general by date

  From Date Subject
Next Message Hunter Hillegas 2002-03-12 22:04:49 Re: Tuning 7.2? Different than 7.1.3?
Previous Message Jeffrey W. Baker 2002-03-12 21:30:16 more about pg_toast growth