stored procedure ing

Results 1 to 3 of 3

Thread: stored procedure ing

  1. #1
    Join Date
    Dec 1969

    Default stored procedure ing

    hi,<BR>i was curiose to know if in a stored procedure. I need to add a record and then find out its ID, if i do it in 2 sql statements ( the code to do it in 1 would be much appreciated ) eg:<BR><BR>insert into ..... ;<BR>select top 1 id from table order by id desc<BR><BR>does the stored procedure between the AS and the GO statements<BR>lock the database so that no one can insert into that particular table and screw up the select so that it gets the wrong record.<BR><BR>P:S i am not calling the stored procedure from asp.

  2. #2
    Jeremy_D Guest

    Default RE: stored procedure ing

    This method will cause problems if multiple inserts (by multiple users) are done at the same time (IOW, no, the table does not stay locked between the two statements).<BR><BR>I assume the id column is defined as an identity? If that is the case, you can do a "SELECT @@IDENTITY" right after the INSERT statement, which should give you the identity of the last INSERT on the current connection. To be absolutely sure I always wrap statement pairs like this in a transaction, but theoretically that would not be necessairy.<BR><BR>Jeremy<BR>

  3. #3
    Join Date
    Dec 1969

    Default Look here... Tips & Tricks section.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts