Thread: primary + foreign key
Hi, I want to create a table where the 2 columns are both primary as well as foreign key. What is the correct syntax for that? Thanks Huub
Huub wrote: > Hi, > > I want to create a table where the 2 columns are both primary as well as > foreign key. What is the correct syntax for that? > > Thanks > > Huub create table detail ( id1 integer, id2 integer, CONSTRAINT c1 PRIMARY KEY(id1,id2), CONSTRAINT c2 FOREIGN KEY(id1,id2) REFERENCES master ); Do you really need such detail table? You can just add columns to master table. Tomasz Myrta
Hi, I suppose 'detail' is the table name? And what is master? Thanks Huub > create table detail > ( > id1 integer, > id2 integer, > CONSTRAINT c1 PRIMARY KEY(id1,id2), > CONSTRAINT c2 FOREIGN KEY(id1,id2) REFERENCES master > ); > > Do you really need such detail table? You can just add columns to master > table. > > Tomasz Myrta > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html
Huub wrote: > Hi, > > I suppose 'detail' is the table name? And what is master? > > Thanks > > Huub You should know that. Detail is a table you want to create and master is a table where foreign key points to. Tomasz Myrta
Thanks for pointing out. I'm not that experienced in SQL yet; so detail could as well be some extra instruction and I've never seen 'references master' before. But I think I'll manage now. Thanks Tomasz Myrta wrote: > Huub wrote: > > >>Hi, >> >>I suppose 'detail' is the table name? And what is master? >> >>Thanks >> >>Huub > > > You should know that. > Detail is a table you want to create and master is a table where foreign > key points to. > > Tomasz Myrta > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster
On Thu, Dec 12, 2002 at 10:54:21AM +0100, Huub wrote: > Thanks for pointing out. I'm not that experienced in SQL yet; so detail > could as well be some extra instruction and I've never seen 'references > master' before. But I think I'll manage now. Thanks Read "An Introduction to Database Systems" by C.J. Date. -Roberto -- +----| Roberto Mello - http://www.brasileiro.net/ |------+ + Computer Science Graduate Student, Utah State University + + USU Free Software & GNU/Linux Club - http://fslc.usu.edu/ + Wasn't dat special?
On Thu, 2002-12-12 at 10:27, Roberto Mello wrote: > > Read "An Introduction to Database Systems" by C.J. Date. > Boy that brings back memories. I think I will dig it out of a box since I am doing database coding again after a long hiatus. Seems like I had a couple of Date books on my shelf at on time. After lurking several pgsql lists for a while now I see why the db2 dbas used to get so bent out of shape with boneheaded queries. Especially since each project got billed for MVS CPU time :) Bret