Is there a better way to retrieve unique ID upon INSERT?

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-04-24T06:32:58Z Indexed on 2010/04/24 6:33 UTC
Read the original article Hit count: 204

Filed under:
|

Hi, I am using the following MS SQL statement to insert records and return the unique auto-inc ID value all in one shot. Wonder if there is a simpler/faster/better way to do it?

SET NOCOUNT ON;

DECLARE @res table (ID bigint);

INSERT INTO [Titles] ([Name],[Timestamp],[Title])
OUTPUT INSERTED.ID INTO @res
VALUES ('Name','23 aug 2010','this is a title');

SELECT [ID] FROM @res;

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about insert