Home > Database > Mysql Tutorial > SqlServer 在事务中获得自增ID

SqlServer 在事务中获得自增ID

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:34:01
Original
1759 people have browsed it

感谢lee576的分享精神,代码如下: USE tempdbgoCREATE TABLE table1( id INT, employee VARCHAR(32))goINSERT INTO table1 VALUES(1, one)INSERT INTO table1 VALUES(2, two)INSERT INTO table1 VALUES(3, three)INSERT INTO table1 VALUES(4, four)GOCREATE

感谢 lee576 的分享精神,代码如下:

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

--=================================
--  用OUTPUT把ID插入@MyTableVar
--=================================
DECLARE @MyTableVar TABLE
(
    id INT
)

INSERT INTO table2 (employee) 
OUTPUT INSERTED.id INTO @MyTableVar
SELECT employee FROM table1

--=================================
--  查询@MyTableVar
--=================================
SELECT * FROM @MyTableVar

--DROP TABLE table1,table2
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Problem with tp6 connecting to sqlserver database
From 1970-01-01 08:00:00
0
0
0
Unable to connect to SQL Server in Laravel
From 1970-01-01 08:00:00
0
0
0
Methods of parsing MYD, MYI, and FRM files
From 1970-01-01 08:00:00
0
0
0
SQLSTATE: User login failed
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template