白板的微信
一、可以用游标,一条条insert,每次两个表。二、关联表更新,增加一个源表主键Xid use testdb2go/*******************建立测试数据***3w@live.cn***********************/IF NOT OBJECT_ID('[TBXXX]') IS NULL DROP TABLE [TBXXX]GOCREATE TABLE [TBXXX]([Xid] int identity(1,1) primary key,[A1] NVARCHAR(20) null,[A2] NVARCHAR(20) null,[B1] Nvarchar(10) null,[B2] NVARCHAR(20) null)goINSERT INTO TBXXXSELECT 'a1',replicate('A1',6),replicate('B1',4),replicate('B1',5) union ALLSELECT 'a2',replicate('A2',6),replicate('B2',4),replicate('B2',5) union ALLSELECT 'a3',replicate('A3',6),replicate('B3',4),replicate('B3',5) union ALLSELECT 'a4',replicate('A4',6),replicate('B4',4),replicate('B4',5) goIF NOT OBJECT_ID('[tbA]') IS NULL DROP TABLE [tbA]GOCREATE TABLE [tbA]([Aid] int identity(1,1) primary key,[A1] NVARCHAR(20) null,[A2] NVARCHAR(20) null,[Xid] int null)goIF NOT OBJECT_ID('[tbB]') IS NULL DROP TABLE [tbB]GOCREATE TABLE [tbB]([Bid] int identity(1,1) primary key,[B1] Nvarchar(10) null,[B2] NVARCHAR(20) null,[Aid] int null,[Xid] int null)goinsert into [tbA] select A1, A2,XId from [TBXXX]insert into [tbB] (Aid,Xid) select AID,Xid from [tbA]----select * FROM [tbB]update [tbB] SET B1=t.B1,B2=t.B2FROM [TBXXX] t INNER JOIN [tbB] on t.Xid=[tbB].XidALTER table [tbA]drop column XidGOALTER table [tbB]drop column XidGOSELECT * FROM [tbA]select * FROM [tbB]