Re: Re: Get Last ID Inserted

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ahh, thanks very much.

On Thu, 2002-11-21 at 12:08, David Elliott wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hello Adam
> 
> On 21 November 2002 at 11:12:46 -0500 (which was 16:12 where I live) Adam
> Voigt rearranged electrons to get
> 
> > But if there are heavy operations on the site, will this not also pick
> > up a different last inserted id, if in the split milisecond between the
> > insert and the next mssql_query which has the @@identity say, another
> > user does an insert?
> 
> No. It picks up the last identity on that connection. So it does not mater
> how many other connections and what they are doing.
> 
> It can only be wrong if you close off the connection and open another one.
> The other way is to put it all into one SQL statement (as long as you don't
> use mssql_????? functions in PHP)
> 
> e.g. (one I used earlier)
> 
> ==========8<=============================================================
> begin transaction
> 
> set nocount on
> 
> declare
>   @NewId int
> 
> update item
> set name = 'Canada Delivery'
> where itemid = '428'
> 
> insert into item
> (ItemTypeId, Name, LastUpdated)
> values
> (49,'Mexico Delivery',getutcdate())
> 
> set @NewId = @@identity
> 
> insert into DelArea
> (itemid,StdEUR, StdGBP, StdUSD, HotEUR, HotGBP, HotUSD)
> values
> (@NewId,37,19,45,134,70,70)
> 
> Update country
> set DelId = @NewId
> where itemid = 288
> 
> commit
> 
> select
>   @NewId NewDelId
> 
> ==========8<=============================================================
> 
> 
> 
> - --
>  Ti2GO,                    _______________________________________________
>   David                   |    David  Elliott    |   Software Engineer    |
>  _________________________| david@elliott.uk.com | PGP Key ID 0x650F4534  |
> | Do you think someone was BORGED when they made these up?                |
> 
> -----BEGIN PGP SIGNATURE-----
> Version: 6.5.8ckt http://www.ipgpp.com/
> 
> iQA/AwUBPd0TBPmK8eZlD0U0EQL1awCgmS57QwyvS+bz02XsLQtwJOSGSB8AoLmo
> I9VdgNIsp3GXkzWAX6I1jYpp
> =UXBQ
> -----END PGP SIGNATURE-----
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
-- 
Adam Voigt (adam@cryptocomm.com)
The Cryptocomm Group
My GPG Key: http://64.238.252.49:8080/adam_at_cryptocomm.asc

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux