Re: Foreign Key for multi PK or design question

From: PostgreSQL Admin <postgres(at)productivitymedia(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Foreign Key for multi PK or design question
Date: 2007-12-11 19:12:38
Message-ID: 475EE126.5030302@productivitymedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

Does this look correct? or most efficient?

J

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Alvaro Herrera 2007-12-11 19:42:46 Re: Foreign Key for multi PK or design question
Previous Message A. Kretschmer 2007-12-11 18:53:30 Re: Foreign Key for multi PK or design question