Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can use Scope_Identity() to get the last identity value inserted into an identity column. But how can i get identity values of all rows which are inserted in a insert statement?


insert into DestinationTbl select * from SourceTbl where [col1]='xyz'

Above statement may insert more than one rows into a table. So i want identity value of all the rows which are inserted. How it can be done?

share|improve this question
up vote 6 down vote accepted

You can use the output clause to throw the inserted rows into a table variable. Then you'll be able to see all of the identity values.

Link for the output clause:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.