View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 10:23 AM
Peter H. Coffin
 
Posts: n/a
Default Re: Newbie trying to understand unique/foriegn keys & joins

On Mon, 06 Aug 2007 22:40:03 -0700, KC wrote:
>
>> Nope, the foreign key isn't populated automagically. You have to assign
>> the value in the first place to the dependant record. But once you do
>> that, then some additional things *can* happen automagically (depending
>> on a few different things).

>
> Thank you Peter,
>
> Is there a best practice for assigning a value? Re entering the
> foreign key data could lead to typo errors couldn't it. Sorry I'm
> really not as dim as I might seem (although I do feel it).
>


We arrange quotes this way here.

If you're creating the value that will be used as the joining value
yourself programmatically, just hang onto the value.

If you're adding a child row later, you can use a subquery to find the
parent record's id.

If you want to put a child record on immdiately after creating the
parent record, you can use the LAST_INSERT_ID() function to retrieve the
value.

If you're typing it in by hand, use a copy-paste routine.

--
6. I will not gloat over my enemies' predicament before killing them.
--Peter Anspach's list of things to do as an Evil Overlord
Reply With Quote