日期:2014-05-17 浏览次数:20813 次
SET IDENTITY_INSERT dt2.dbo.t2 on;
insert dt2.dbo.t2(ID,col1.......)--指定所有列名
select * from t1
SET IDENTITY_INSERT dt2.dbo.t2 off;
舉個例子給樓主參照
USE tempdb
GO
CREATE TABLE T1(ID INT IDENTITY(10,1))
GO
CREATE TABLE T2(ID INT identity)
INSERT INTO t1 DEFAULT VALUES
go
INSERT INTO t2 DEFAULT VALUES
go 3
/*
T1:
-----
10
T2:
--
1
2
3
*/
SET IDENTITY_INSERT t2 ON;
INSERT t2(ID) SELECT * FROM t1
SET IDENTITY_INSERT t2 Off ;
/*
T2:
1
2
3
10
*/
INSERT INTO t2 DEFAULT VALUES
/*
T2:
1
2
3
10
11
*/
--SELECT * FROM t1
--SELECT * FROM t2
--DROP TABLE t1,t2