2013-09-25 7 views

回答

0
SET IDENTITY_INSERT tablename ON /* on destination table */ 


INSERT INTO database2.table2 (ColA, ColB, ColC) select ColA, ColB, ColC database1.table1 


SET IDENTITY_INSERT tablename OFF /* on destination table */ 
+0

只是這樣將數據插入一個名爲table2的存在表中。現在我想知道如何將數據插入到不存在的表中,並將其主鍵每次自動加1。 – Lyly

0
select * into database2.table2 from database1.table1 
alter table table2 alter column id int identity(1,1) not null 
alter table table2 add constraint pkid primary key (id) 
如果你想保持數據的數據庫/表之間的一致
相關問題