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>)
Список pgsql-novice
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'sid into the child's foreign key -> done.  this is pretty simple and straightforward once you get the code
nomenclaturedown. 

as Richard pointed out, once you start entering the child first, things get more complex.  i'd recommend evaluating
whetherthe "enter the child record first" constraint is really a required constraint.  if not, drop it, enter the
parentfirst, 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*
actuallyrequired 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
Дата:
Сообщение: Re: Using a serial primary key as a foreign key in a second table
Следующее
От: Patrick
Дата:
Сообщение: Re: Using a serial primary key as a foreign key in a second