Re: Can a field be a primary key as well as a foreign key? - Mailing list pgsql-general

From Jan Wieck
Subject Re: Can a field be a primary key as well as a foreign key?
Date
Msg-id 200203122145.g2CLjTU31327@saturn.janwieck.net
Whole thread Raw
In response to Can a field be a primary key as well as a foreign key?  (Andrew Snow <andrew@modulus.org>)
List 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@Yahoo.com #



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


pgsql-general by date:

Previous
From: "Jeffrey W. Baker"
Date:
Subject: more about pg_toast growth
Next
From: Hunter Hillegas
Date:
Subject: Re: Tuning 7.2? Different than 7.1.3?