James Newtons Massmind wrote: >>> Thanks. Yeah, I already had that one, but it is painfully slow for >>> some strange reason... The more I look at it, I think there is >>> something going on with the server that is slowing it >>> >> down... Time to >> >>> scandisk, defrag, rebuild, clean, etc... >>> >> And load Informix. :-) >> >> Heh heh... just kiddin' James. >> >> Sorry you're having trouble. >> >> > > No worries, after a rebuild (which took less time than I expected) it is > down right peppy, so I guess I just need to do a better job of keeping up > with regular maintenance. > > No the trick is to figure out if > > SELECT @@IDENTITY AS 'ID'; > > Will work correctly outside of a stored procedure or do I have to write one > to insert into the main table and then record that ID and the users ID into > the table of who added what and when. > > My concern is that if someone else writes to the database or even to that > table between when I insert and then read the identity, do I get my ID or > their ID? > > It hinges on how the work "session" from > http://msdn2.microsoft.com/en-us/library/ms187342.aspx relates to separate > ado commands on the same connection. > > Why the heck couldn't INSERT have been defined so that it could return data? > E.g. > > If you have a table with columns a, b, c, and ID which is an identity, then: > > INSERT INTO table (a,b,c) VALUES (1,2,3) RETURN ID; > > Would produce a recordset with one column "ID" and the one entry would be > the identity of the new record. > > If only I ran the world... > > --- > James. > > > The @@IDENTITY will return the identity value of the last record inserted in the current connection (i.e. *not* the record inserted by someone else) i.e. (again), it works the way that makes sense. As for the insert you want to do, well, @@IDENTITY is normally used most in stored procedures, so, build a procedure to do the obvious.... See http://msdn2.microsoft.com/en-us/library/ms187926.aspx or, it seems a function even, hmmm...no, functions are not allowed to modify the database... so, no inserts. But, output parameters on the procedures will work fine. Rolf -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist