感謝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
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com