Select

Question:
I have a table with three columns. The first, an integer type, is the primary key that is automatically increased by one every time a new row is inserted. What I want to do is insert a row, then somehow get its newly created ID. Is it possible? (I would like to do this without using the cursor.)

Answer:
Whenever a row is inserted to a column with an identity field, the system variable @@IDENTIY is set to the value of the identity field. After the insert just execute a select @@IDENTITY.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: