Re: [GENERAL] Question on Foreign Key Structure/Design

2009-05-25 Thread Johan Nel
APseudoUtopia wrote: 2. I do not want to get rid of any comments, even if the user is deleted (on the application level, I'd display something like UnknownUser or UnknownUser#1234). Right now, I just have it ON DELETE RESTRICT, but that obviously prevents any users who have commented from being d

Re: [GENERAL] Question on Foreign Key Structure/Design

2009-05-24 Thread Craig Ringer
APseudoUtopia wrote: > 1. Do I need "NOT NULL" in the comments(userid) column? Yes, unless you want it to be possible for a comment to have a NULL `userid' field. Foreign key REFERENCES state that _if_ there is a value in the referencing field, it must exist in the referenced key. The foreign ke

Re: [GENERAL] Question on Foreign Key Structure/Design

2009-05-24 Thread Adam Rich
APseudoUtopia wrote: Hey list, I have a table with user IDs, among other information. I also have a table of comments that users can place on a page. CREATE TABLE "users" ( "id" SERIAL PRIMARY KEY, ... ); CREATE TABLE "comments" ( "id" SERIAL PRIMARY KEY, "userid" INTEGER REFERENCES "use

[GENERAL] Question on Foreign Key Structure/Design

2009-05-24 Thread APseudoUtopia
Hey list, I have a table with user IDs, among other information. I also have a table of comments that users can place on a page. CREATE TABLE "users" ( "id" SERIAL PRIMARY KEY, ... ); CREATE TABLE "comments" ( "id" SERIAL PRIMARY KEY, "userid" INTEGER REFERENCES "users" ("id") ON DELETE REST