Re: Using a serial primary key as a foreign key in a second table

Поиск
Список
Период
Сортировка
Искать
От
Тема
Re: Using a serial primary key as a foreign key in a second table
Дата
Msg-id
20061221203942.46268.qmail@web33313.mail.mud.yahoo.com
Список
Дерево обсуждения
Using a serial primary key as a foreign key in a second table Nathaniel <naptrel@yahoo.co.uk>
Re: Using a serial primary key as a foreign key in a second table Sean Davis <sdavis2@mail.nih.gov>
Re: Using a serial primary key as a foreign key in a second table Nathaniel <naptrel@yahoo.co.uk>
Re: Using a serial primary key as a foreign key in a second table Sean Davis <sdavis2@mail.nih.gov>
Re: Using a serial primary key as a foreign key in a second table Nathaniel <naptrel@yahoo.co.uk>
Re: Using a serial primary key as a foreign key in a second table Sean Davis <sdavis2@mail.nih.gov>
Re: Using a serial primary key as a foreign key in a second table Richard Broersma Jr <rabroersma@yahoo.com>
Re: Using a serial primary key as a foreign key in a second table Bruno Wolff III <bruno@wolff.to>
Re: Using a serial primary key as a foreign key in a second Patrick <flymooney@gmail.com>
Subject: Re: [NOVICE] Using a serial primary key as a foreign key in a second table

When I want to add  an "object", I add a row to one of the three child tables (depending  
on the type of object I'm adding) and then add a record to the parent  class table...
        
---------------------------------------------------

Nathaniel,

is there some kind of constraint that absolutely requires you to enter the child record before the parent record?

the customary way to do this is to add (or select) the parent, get its unique id, add the child(ren) and insert the parent's id into the child's foreign key -> done.  this is pretty simple and straightforward once you get the code nomenclature down.

as Richard pointed out, once you start entering the child first, things get more complex.  i'd recommend evaluating whether the "enter the child record first" constraint is really a required constraint.  if not, drop it, enter the parent first, the child second and bask in the simplicity of the solution. 

if a "child first" constraint is absolutely required the, well, you gotta do what you gotta do.  just make sure it *is* actually required before going through the hassle of "doing what ya gotta do."

good luck.




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com
В списке pgsql-novice по дате отправления
От: Bruno Wolff III
Дата:
От: Patrick
Дата:
FAQ