2008/4/11, Matt Emson <[EMAIL PROTECTED]>: > Michael Van Canneyt wrote: > > > And it is exactly why I can't use MySQL, MSSQL: they don't have sequences > or > > generators. I need the ID BEFORE I insert the record, not after. > > > > > > YES!! This is also missing from SQL Server... or at least, using a GUID is > complete overkill. The mechanisms SQL Server has for retrieving the last > interted identity value are completely unsane too. Yes, they do work, but > things get tricky in real world situations. I have no idea how anyone wrote > reliable code to insert a record and retern the IDENTITY value prior to SQL > Server 2005. > > OT: does anyone know of a reliable generator style "atomic" robust multi > user friendly auto IDENTITY generation mechanism for SQL Server? I'd love to > be able to define one, but I don't think I have seen one yet that *really* > works well.
Have you try SCOPE_IDENTITY() ? Available at least since SQL SERVER 2000. I have used it with success. from MSDN : <quote> Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch. </quote> Interesting article ( 10 Things You Shouldn't Do with SQL Server ) : http://www.sqljunkies.ddj.com/Article/92CC4817-604D-4344-8BE0-4490F8ED24B6.scuk -- Inoussa O. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal