Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I'm trying to get a the key-value back after an INSERT-statement. Example: I've got a table with the attributes name and id. id is a generated value.

 INSERT INTO table (name) VALUES('bob');

Now I want to get the id back in the same step. How is this done?

We're using Microsoft SQL Server 2008.

1 Answer

0 votes
by (40.7k points)
edited by

You can use the code given below, instead of using separate SELECT.

Are you interested in learning SQL from the basics! Refer to this video on SQL provided by Intellipaat:

Query:

INSERT INTO table (name)

OUTPUT Inserted.ID

VALUES('bob');

The above code only works for Non-IDENTITY columns.

Related questions

Browse Categories

...