有这样2个表
maintableCREATE TABLE [dbo].[maintable] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[content] [char] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GOCREATE 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 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
4 op1 2007-07-20 15:05:47
4 op2 2007-07-20 15:05:47
4 op3 2007-07-20 15:05:47
4 op4 2007-07-20 15:05:47
5 op1 2007-07-20 15:06:33
5 op2 2007-07-20 15:06:39
5 op3 2007-07-20 15:07:08
5 op4 2007-07-20 15:07:15
6 op1 2007-07-20 15:07:43
6 op2 2007-07-20 15:07:51
6 op3 2007-07-20 15:07:54
6 op4 2007-07-20 15:07:57不知道如何实现。最主要把数据库B的maintable数据导入到数据库A中,id不会自增。
望高手帮忙和有有相关经验者提供帮助。
maintableCREATE TABLE [dbo].[maintable] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[content] [char] (10) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GOCREATE 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 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
4 op1 2007-07-20 15:05:47
4 op2 2007-07-20 15:05:47
4 op3 2007-07-20 15:05:47
4 op4 2007-07-20 15:05:47
5 op1 2007-07-20 15:06:33
5 op2 2007-07-20 15:06:39
5 op3 2007-07-20 15:07:08
5 op4 2007-07-20 15:07:15
6 op1 2007-07-20 15:07:43
6 op2 2007-07-20 15:07:51
6 op3 2007-07-20 15:07:54
6 op4 2007-07-20 15:07:57不知道如何实现。最主要把数据库B的maintable数据导入到数据库A中,id不会自增。
望高手帮忙和有有相关经验者提供帮助。
3. 修改B中id的值
update maintable set id=id+maxid
update othertable set id=id+maxid3. 將修改的記錄import 到A中或用insert語句插入A中都可以.