From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: PostgreSQL Admin <postgres@productivitymedia.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Foreign Key for multi PK or design question
Date: Tue, 11 Dec 2007 16:42:46 -0300
Message-ID: <20071211194246.GK10710@alvh.no-ip.org> (raw)
In-Reply-To: <475EE126.5030302@productivitymedia.com>
References: <863ECFDF04C8804ABDF3559D87F157C638E5D9@MAGPTCPEXC02.na.mag-ias.net>
<475ED504.7080006@productivitymedia.com>
<20071211185330.GA16159@a-kretschmer.de>
<475EE126.5030302@productivitymedia.com>
PostgreSQL Admin wrote:
> This is my layout so far:
>
> CREATE TABLE users (
> id serial NOT NULL,
> --question REFERENCES questions(id) ON DELETE CASCADE ## ON REMOVED##
> );
>
> CREATE TABLE questions (
> id serial NOT NULL,
> questions varchar(450) NOT NULL
> );
>
> CREATE TABLE answers (
> id serial NOT NULL,
> question_id int REFERENCES questions(id) ON DELETE CASCADE,
> user_id int REFERENCES users(id) ON DELETE CASCADE,
> answer varchar(450) NOT NULL,
> created timestamptz NOT NULL
> );
>
> Originally I wanted to have a foreign key that would be the pk of the
> question table. So if the user answered Q2, 5 and 6 - the user.fk would
> store values 2,5,6 - but I have passed most of logic to the answer table.
That would have made no sense.
> Does this look correct? or most efficient?
Yeah it seems sane, however you have forgotten to add NOT NULL to the FK
fields.
--
Alvaro Herrera http://www.PlanetPostgreSQL.org/
"No me acuerdo, pero no es cierto. No es cierto, y si fuera cierto,
no me acuerdo." (Augusto Pinochet a una corte de justicia)
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: pgsql-sql@postgresql.org
Cc: alvherre@alvh.no-ip.org, postgres@productivitymedia.com
Subject: Re: Foreign Key for multi PK or design question
In-Reply-To: <20071211194246.GK10710@alvh.no-ip.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox