You are here: Re: Stored Procedures « PHP Programming Language « IT news, forums, messages
Re: Stored Procedures

Posted by Bruce A. Julseth on 05/03/07 00:48

"NC" <nc@iname.com> wrote in message
news:1178071238.832048.11810@q75g2000hsh.googlegroups.com...
> 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
>

Thanks for the suggestions. I will convert to LAST_INSERT_ID(). Didn't know
about it...

I would like to do it as a stored procedure because I think it's pretty
straight forward. However, I don't know how to write stored procedures. Any
suggestions, or books, I can learn from??

Thanks again..

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация