473,394 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Stored Procedures

I'm new to having to write stored procedures and would appreciate some good
books I can use to learn. I searched Amazon and really wasn't happy with
what I found, but maybe I really didn't know what to look for. My first case
that I'm looking into is updating a relationship. What I am doing now is
straight SQL!!

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??

- Does this make for writing a stored procedure?
- Is there a better way to do it in SQL?

Thanks.....
May 1 '07 #1
4 1708
NC
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

May 2 '07 #2

"NC" <nc@iname.comwrote in message
news:11*********************@q75g2000hsh.googlegro ups.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..
May 3 '07 #3
NC
On May 2, 5:48 pm, "Bruce A. Julseth" <bruceaj_nosp...@bellsouth.net>
wrote:
>
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??
Take a look at the documentation first:

http://dev.mysql.com/doc/refman/5.0/...rocedures.html

Cheers,
NC

May 4 '07 #4

"NC" <nc@iname.comwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
On May 2, 5:48 pm, "Bruce A. Julseth" <bruceaj_nosp...@bellsouth.net>
wrote:
>>
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??

Take a look at the documentation first:

http://dev.mysql.com/doc/refman/5.0/...rocedures.html

Cheers,
NC
I will. Thanks....
May 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
5
by: Rhino | last post by:
I am trying to determine the behaviour of stored procedures in DB2 V8.2.x in Windows/Unix/Linux and how I can control that behaviour. Some documentation in the manuals is confusing the issue...
5
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored...
2
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have...
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
11
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.