关于结构相同,数据不同的数据库进行一个表数据合并入另一个数据库中的表
2015-12-15 10:50
681 查看
首先,进行数据库的操作,这里使用的是ado+access进行的数据库的操作,目前来看,ado这种方式还算是比较简单。
而且网络上关于数据库进行连接的博客有一大推,这里就不做探讨了,这里仅仅说明的是,一个数据库的表复制进入另一个数据库中。
1、关于数据库的复制有两种情况
1)insert into table1 select * from table2
2) select into table 1 select *from table2
这两种写法有什么区别呐,首先insert into这种写法必须有table1这个表格,select则是在access中必须不能存在table1,否则在ado接口中会出现报错的现象。
2、一个数据库对另一个数据库进行复制操作,
sql语句有如下写法:
insert into table1 select distinct * from (select * from table1 union select * from table1 in 'D:\\record1.mdb')a where id =1
这样的意思就是 向已经连接的数据库中的table1 插入(不同的)来自(table1 以及 record1中的table1)a 加上条件的记录
select into
其用法与insert into 相同 不做描述
3、增加点难度,这里说一下where 后面跟两个条件的例子
sql: insert into table1 select distinct * from(selcet * from table1 union selcet *from table1 in 'D:\\record1.mdb')a where id=1 and name=fd
这是两种条件的情况 条件中间必须要加上 and or ,如果有非操作 那么可以加上括号,并且在括号之前加上not
4、继续增加点难度,我们向一个表中复制另一个数据库中的表中的数据,并且不能出现重复的,接下来我们应该怎么做?
根据以上的经验 我们是不是可以用一个条件,这个条件是什么?
sql:insert into table1 select distinct * from(select * from table1 union select * from table1 in 'D:\\record1.mdb')a where not exists (select 1 from table1 where id = a.id)
这里的id为主键,那么我们就可以得到了从另一个数据库中的不重复的记录。
5、接着增加难度,如果我们的数据库当中存在两个主键我们应该怎么办???(并且我们要增加不重复的记录)
根据之前的经验我们是不是可以得出结论了
sql: insert into table select distinct * from(select * from table1 union select * from table1 in 'D:\\record1.mdb')a where not exists (select 1 from table1 where id=a.id and name = a.name)
这就是关于从另一个结构相同的数据库中复制带有两个主键的表中的数据的sql 语句。希望对之后的热能有帮助
而且网络上关于数据库进行连接的博客有一大推,这里就不做探讨了,这里仅仅说明的是,一个数据库的表复制进入另一个数据库中。
1、关于数据库的复制有两种情况
1)insert into table1 select * from table2
2) select into table 1 select *from table2
这两种写法有什么区别呐,首先insert into这种写法必须有table1这个表格,select则是在access中必须不能存在table1,否则在ado接口中会出现报错的现象。
2、一个数据库对另一个数据库进行复制操作,
sql语句有如下写法:
insert into table1 select distinct * from (select * from table1 union select * from table1 in 'D:\\record1.mdb')a where id =1
这样的意思就是 向已经连接的数据库中的table1 插入(不同的)来自(table1 以及 record1中的table1)a 加上条件的记录
select into
其用法与insert into 相同 不做描述
3、增加点难度,这里说一下where 后面跟两个条件的例子
sql: insert into table1 select distinct * from(selcet * from table1 union selcet *from table1 in 'D:\\record1.mdb')a where id=1 and name=fd
这是两种条件的情况 条件中间必须要加上 and or ,如果有非操作 那么可以加上括号,并且在括号之前加上not
4、继续增加点难度,我们向一个表中复制另一个数据库中的表中的数据,并且不能出现重复的,接下来我们应该怎么做?
根据以上的经验 我们是不是可以用一个条件,这个条件是什么?
sql:insert into table1 select distinct * from(select * from table1 union select * from table1 in 'D:\\record1.mdb')a where not exists (select 1 from table1 where id = a.id)
这里的id为主键,那么我们就可以得到了从另一个数据库中的不重复的记录。
5、接着增加难度,如果我们的数据库当中存在两个主键我们应该怎么办???(并且我们要增加不重复的记录)
根据之前的经验我们是不是可以得出结论了
sql: insert into table select distinct * from(select * from table1 union select * from table1 in 'D:\\record1.mdb')a where not exists (select 1 from table1 where id=a.id and name = a.name)
这就是关于从另一个结构相同的数据库中复制带有两个主键的表中的数据的sql 语句。希望对之后的热能有帮助
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- 数据库链接字符串查询网站
- DB2实例管理
- DB2实例管理
- 保障MySQL数据安全的14个最佳方法
- mysql问答汇集
- 创建一个空的IBM DB2 ECO数据库的方法
- Access 2000 数据库 80 万记录通用快速分页类
- 开通一个数据库失败的原因的和解决办法
- 一个简单的asp数据库操作类
- 用VBScript写合并文本文件的脚本
- CentOS下DB2数据库安装过程详解
- EasyASP v1.5发布(包含数据库操作类,原clsDbCtrl.asp)第1/2页
- sql2008 还原数据库解决方案
- Oracle 数据库自动存储管理-安装配置
- Oracle 数据库 临时数据的处理方法
- oracle列合并的实现方法
- 数据库分页查询语句数据库查询