SET IDENTITY_INSERT cityt ON insert into cityt(id,code) select id,code from province where id not in(select id from cityt) SET IDENTITY_INSERT cityt OFF
你的ID是的Int类型 标识为是 的自动编号还重复就奇怪了.
insert into cityt(code) select code from province where id=18
〉〉insert into cityt(code) select code from province where id=18 SET IDENTITY_INSERT cityt ON 只是让你可以在该字段插入数据,而不是帮你自动更改字段数字。
create table t1(id int identity,a int) insert t1 values(1) insert t1 values(2)dbcc checkident ( 't1', reseed,1) insert t1 values(3) select * from t1ID A 1 1 2 2 2 3想不重复,可以不改 identity_insert,就用insert into cityt(code) select code from province where id=18
insert into cityt(id,code) select id,code from province where id not in(select id from cityt)
SET IDENTITY_INSERT cityt OFF
insert t1 values(1)
insert t1 values(2)dbcc checkident ( 't1', reseed,1)
insert t1 values(3)
select * from t1ID A
1 1
2 2
2 3想不重复,可以不改 identity_insert,就用insert into cityt(code) select code from province where id=18