October 27, 2009

A Better Way to Retrieve the ID of the Last Inserted Record

This tip is a follow-up to the tip Retrieving the ID of the Last Inserted Record. In that tip, the SELECT command is longer than it needs to be. Here’s the original: SELECT job_id FROM jobs WHERE job_id = @@IDENTITY To simplify the code, I suggest simply writing: SELECT @@IDENTITY