Re: Foreign Key for multi PK or design question - Mailing list pgsql-sql

From PostgreSQL Admin
Subject Re: Foreign Key for multi PK or design question
Date
Msg-id 475EE126.5030302@productivitymedia.com
Whole thread Raw
In response to Re: Foreign Key for multi PK or design question  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Responses Re: Foreign Key for multi PK or design question
Re: Foreign Key for multi PK or design question
List 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


pgsql-sql by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Foreign Key for multi PK or design question
Next
From: Alvaro Herrera
Date:
Subject: Re: Foreign Key for multi PK or design question