|
Posted by NC on 05/02/07 02:00
On May 1, 12:36 pm, "Bruce A. Julseth" <bruceaj_nosp...@bellsouth.net>
wrote:
>
> What I am doing now is straight SQL!!
Unfortunately, there is no such thing as "straight SQL". Every
implementation is different in details...
> I have Table A that has a link field in it pointing to
> Table B. So, I first "INSERT" into table B, then do
> a SELECT on MAX(Key) where Key is an auto
> incremented field. I then include the value of "Key"
> in the data when I do the INSERT into Table A.
> Make sense??
This is a dangerous approach that can backfire in case of concurrent
updates. Instead of SELECT MAX(key), you should be using
LAST_INSERT_ID() (assuming you are running MySQL, of course...)
> - Does this make for writing a stored procedure?
If you want to do it as a stored procedure, you can.
> - Is there a better way to do it in SQL?
Better in terms of what? Execution time, portability,
maintainability, something else?
Cheers,
NC
Navigation:
[Reply to this message]
|