I have two tables foo and bar, foo has an auto incremented field colA. I need to insert a record in foo and get the auto incremented value then insert into bar(foreign key). With postgresql it was a simple single query, but where as in SQL server I am not able to find right query.
Postgresql
With row as (insert into foo(colB) values('x') RETURNING colA ) insert into bar(colA) select colA from row
Is there any way to achieve in MsSql using single query?
Server version details
DBMS: Microsoft SQL Server (ver. 13.00.5882)
Driver: Microsoft JDBC Driver 8.2 for SQL Server (ver. 8.2.2.0, JDBC4.2)