db2中create table as的建表方式
来源:互联网 发布:哪个软件免费下载音乐 编辑:程序博客网 时间:2024/06/05 11:05
DB2没有类似oracle的create table as select来定义表的方式,所以DB2中把SELECT查询出来的结果定义为别的表比较麻烦!
DB2定义表的3种方式:
首先创建一个例子表,再插入几条语句。
create table t1(col1 varchar(10));create table t2 (col1 varchar(10),col2 varchar(20));insert into t1 values ('1');insert into t2 values ('1','ZXT');describe select t1.col1,t2.col2 from t1,t2 where t1.col1=t2.col2;
一:按照常规的形式定义
首先describe sql,得到DDL,可以如下进行(describe select t1.col1,t2.col2 from t1,t2where t1.col1=t2.col2;)
然后根据DDL来创建table,最后把数据insert 过去。
二:汇总表方式
需要3个步骤:
1.创建汇总表
create table tt as ( select t1.col1,t2.col2 from t1,t2 where t1.col1=t2.col2 )data initially deferred refresh deferred;
2.刷新数据
refresh table tt;
3.把汇总表改成一般的表
alter table tt drop materialized query;这个方法比较常用,好使没啥好说的,而且可以一次性就把数据刷新过去!
三:只定义表结构的形式
需要2个步骤:
1.创建表---只定义表结构
create table tt as ( select t1.col1,t2.col2 from t1,t2 where t1.col1=t2.col2 ) definition only;
注:此步骤只定义了表结构,类似于oracle 的create XX as 语句
2.插数据过来
insert into tt select t1.col1,t2.col2 from t1,t2 where t1.col1=t2.col2;这是一个比较笨的方法,没什么好说的!今天总结了其他2中方法,现在分享给大家。
还有一种就是通过游标load进另外一个表中(采用游标,数据不需落地)
DECLARE mycursor CURSOR FOR SELECT col1, col2 FROM t2;LOAD FROM mycursor OF CURSOR INSERT INTO t3;
0 0
- db2中create table as的建表方式
- db2 中通过查询结果来create table 的3种方式
- db2 中通过查询结果来create table 的3种方式
- DB2的create table like
- db2中可以实现create table A as select * from B吗?
- mysql/oracle中create table as的用法
- create table as 在Ogg中测试
- oracle create table xx as select ....CREATE TABLE XXX AS SELECT .... 拷贝表的时候 not null 约束 和check
- create table as 产生的问题
- Oracle create table as 的坑
- create table as......
- 当心 CREATE TABLE AS
- create table as
- CREATE TABLE AS
- create table .... as注意事项
- Create table as select
- create table as select
- create table table_name as ...
- linux下Mysql 的安装、配置、数据导入导出
- string和stringBuilder区别
- 关于jar,war,ear包
- python 装饰器 面向切面
- Linux (ubuntu) Study Note
- db2中create table as的建表方式
- Tornado http服务器篇
- 项目视频讲解_郑印-HDPHP团购网开发(美团网)
- 敏捷之旅2013北京站总结 - 演讲嘉宾ppt汇总篇
- Qt下使用OpenGL(16)-根据NeHe的教程改写的
- CString相关
- Linux telnet命令的使用
- googe眼镜开发
- vim taglist 使用