SQL Server obtains the instance code of the auto-increment ID in the transaction. SQL server instance
SqlServer obtains the auto-incremental ID instance code in the transaction
There are many ways to return the auto-increment primary key ID when inserting data in sqlserver. Here we provide one.
The Code is as follows:
USE tempdb go create table table1 (id INT, employee VARCHAR (32) go insert into table1 VALUES (1, 'one') insert into table1 VALUES (2, 'two ') insert into table1 VALUES (3, 'three ') insert into table1 VALUES (4, 'four') go create table table2 (id int identity (1, 1), employee VARCHAR (32 )) GO -- ======================================================= -- use OUTPUT insert @ MyTableVar -- ================================== DECLARE @ MyTableVar TABLE (id INT) insert into table2 (employee) output inserted. id INTO @ MyTableVar SELECT employee FROM table1 -- ============================== ==-- query @ MyTableVar -- ====================================== SELECT * FROM @ MyTableVar -- drop table table1, table 2
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!