日期:2014-05-19  浏览次数:20501 次

问一个数据迁移的问题。
有这样2个表
maintable

CREATE   TABLE   [dbo].[maintable]   (
[id]   [int]   IDENTITY   (1,   1)   NOT   NULL   ,
[content]   [char]   (10)   COLLATE   Chinese_PRC_CI_AS   NULL  
)   ON   [PRIMARY]
GO

CREATE   TABLE   [dbo].[othertalbe]   (
[id]   [int]   NULL   ,
[opname]   [char]   (10)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[date]   [datetime]   NULL  
)   ON   [PRIMARY]
GO
其中maintable为主键表,主键为id。othertable为外键表,外键为id。

现有2个数据库:数据库A,数据库B。其中都有maintable,othertable这2个表。
其中数据库A中
maintable   数据若下
1 test1          
2 test2          
3 test3          
othertable数据如下
1 op1               2007-07-20   15:05:47
1 op2               2007-07-20   15:05:47
1 op3               2007-07-20   15:05:47
1 op4               2007-07-20   15:05:47
2 op1               2007-07-20   15:06:33
2 op2               2007-07-20   15:06:39
2 op3               2007-07-20   15:07:08
2 op4               2007-07-20   15:07:15
3 op1               2007-07-20   15:07:43
3 op2               2007-07-20   15:07:51
3 op3               2007-07-20   15:07:54
3 op4               2007-07-20   15:07:57


但是数据库B内容如下:
maintable   数据若下
1 test4          
2 test5        
3 test6  
othertable数据如下
1 op1               2007-07-20   15:05:47
1 op2               2007-07-20   15:05:47
1 op3               2007-07-20   15:05:47
1 op4               2007-07-20   15:05:47
2 op1               2007-07-20   15:06:33
2 op2               2007-07-20   15:06:39
2 op3               2007-07-20   15:07:08
2 op4               2007-07-20   15:07:15
3 op1               2007-07-20   15:07:43
3 op2               2007-07-20   15:07:51
3 op3               2007-07-20   15:07:54
3 op4               2007-07-20   15:07:57
  现要求将B数据库内容整合到数据库A中,
整合后要求如下数据内容为

maintable   数据若下
1 test1          
2 test2          
3 test3          
4 test4          
5 test5        
6 test6  
othertable数据如下
1 op1   &nbs