MySQL Forums
Forum List  »  Stored Procedures

Re: LAST_INSERT_ID() question.
Posted by: peter.hamilton-scott
Date: November 06, 2005 12:26PM

Roland,

I was thinking of doing something on the lines of calling my SP which would receive input parameters and using that to insert the record which in turn activates the trigger which in turn inserts its audit record. Then when the SP insert has completed I could get the last id and do a select on it and that would be the recordset (single row, single column) which my main program can then retrieve. I'd do that in C# by executing the SP call as a scalar result so I could simply cast the result into a long integer and the main program can do with it as required.

I like the idea you suggested of getting the last id before the trigger does its insert but how could I get that value back to the SP? I believe triggers are synchronous meaning when the trigger is activated the SP does nothing more until the trigger completes?

The thing I'm not sure of is how I get the id # back to the SP if there is no concept of a trigger parameter list? Is this where I would use a, for example, @mylastid session variable and let the trigger set it and then the SP can read it using a select statement?

Options: ReplyQuote


Subject
Views
Written By
Posted
3302
November 05, 2005 04:05PM
1983
November 05, 2005 05:33PM
1914
November 06, 2005 02:01AM
2474
November 06, 2005 07:20AM
Re: LAST_INSERT_ID() question.
1996
November 06, 2005 12:26PM
1903
November 06, 2005 12:44PM
2904
November 06, 2005 04:52PM
1937
November 06, 2005 06:45PM
1809
November 07, 2005 01:44AM
1829
November 07, 2005 09:27AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.