查看所有表
!table
查看表结构
!desc table_name
创建schema(相当于数据库)
create schema wndb;create schema wndb2;
创建表
CREATE TABLE wndb.wnuser (id varchar PRIMARY KEY,account varchar ,passwd varchar);CREATE TABLE wndb2.wnuser (id varchar PRIMARY KEY,account varchar ,passwd varchar);
插入数据
upsert into wndb.wnuser values ('001', '12', '34');upsert into wndb.wnuser values ('002', '123', '34');
upsert into wndb.wnuser values ('003', '124', '34');
upsert into wndb.wnuser values ('004', '125', '34');
upsert into wndb.wnuser values ('005', '126', '34');
upsert into wndb.wnuser values ('009', '126', '34');
upsert into wndb.wnuser values ('012', '126', '34');
---------------------------------------------------------
upsert into wndb2.wnuser select * from wndb.wnuser;
upsert into wndb2.wnuser values ('006', '126', '34');
upsert into wndb2.wnuser values ('007', '126', '34');
upsert into wndb2.wnuser values ('008', '126', '34');
upsert into wndb2.wnuser values ('010', '126', '34');
upsert into wndb2.wnuser values ('022', '126', '34');
查询插入数据
select * from wndb.wnuser;select * from wndb2.wnuser;
创建视图
create view view_user_all asselect * from (
select id, account, passwd from wndb.wnuser
union all
select id, account, passwd from wndb2.wnuser); (报错)
问题:
1. 只能使用一个select, 下一个select会提示结束符
2. 且不能出现括号 (
所以使用 union all 一步创建两张表的视图不行
采用下面方法:
先创建有表1的视图
create view wndb.view_user_all as
select * from wndb.wnuser;
再在视图插入表2的数据(插入视图的数据实际上都插入到表1了)
upsert into view_user_all select * from wndb2.wnuser;
问题: 只有第一张表和视图同步更新, 第二张表不同步更新(因为插入视图实际上就是把数据手动插入到了表1中)
所以每次第二张表更新的时候, 需要重新执行插入语句
所以这个方法肯定不行
结论:一个视图只能由一个表创建
创建视图正解create view wndb.view_user_all as
select * from wndb.wnuser;