Hi all,
is there a way in SQL Server for me to get the next available Identity value from an Identity column?
(Idon'twant to perform an insert, and then get the identity through @.@.IDENTITY!)
Thanks
Tryst
SELECT (IDENT_CURRENT('tableName') + 1)
But this is not safe! If 2 processes call this they can get the same ID number.
|||OK - Thanks Darrel.
I may have to give that a miss then, esp is it nots 100% secure.
Thanks
Tryst
|||I was assuming you were reading it and then returning it to yourbusiness object and waiting a while. If you are getting the IDnumber and then immediately updating, then you could wrap it in atransaction and set thetransaction levelto serializable. That would decrease throughput, but if you'renot supporting that many users, maybe it's ok. -- But if that'sall you're doing, why not use autonumber?
|||Hi Darrell,
what I am doing is inserting an entry into the database, where theentry will contain a column that will reference the primary key to thatentry. The idea is that I will be storing XML data in the database, andif the XML data is more than 1024 chars then the XML will be spreadacross multiple rows. Therefore, I need a Column that tells me what rowthese XML rows relate to (which is the first row that contain the XMLdata). I then have an order column which will determine the order I canassemble the XML data from these rows. So, my problem was, for thefirst row that will contain XML data that will span multiple rows (oreven singular rows - XML data < 1024 chars) how do I get to know theprimary for this entry so that I can insert it into the referencecolumn. The way I done this was to do an insert, and then quicklyfollowed by an update after using @.@.IDENTITY.
Thanks
Tryst
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment