SELECT * FROM hjtest.user;
SELECT * FROM hjtest.oppotunity;
#单表视图
create view `hjTest`.`user_view`
as
select userid, username from hjtest.user;
#1,支持查询
select * from `hjTest`.`user_view` where userid=10;
#2,支持单表插入
insert into `hjTest`.`user_view`(`userid`, `username`)
values(10,'newuser');
#3,支持单表更新
update `hjTest`.`user_view` set username='Jackson' where userid=2;
#4,支持单表删除
delete from `hjTest`.`user_view` where userid=10;
#笛卡儿积关联视图
create view `hjTest`.`user_oppo`
as
select userid, username, opid, opname from hjtest.user, hjtest.oppotunity;
#1,支持查询
select * from `hjTest`.`user_oppo` where userid=1;
#2,支持对视图所关联的其中一个表的插入(单表插入)
insert into `hjTest`.`user_oppo`(`userid`, `username`)
values(11,'onlyUser');
#3,不支持多表的同时插入
insert into `hjTest`.`user_oppo`(`userid`, `username`, `opid`, `opname`)
values(10,'newuser',10,'newop');
#4,支持对视图所关联的其中一个表的更新(单表更新)
update `hjTest`.`user_oppo` set username='Catherine' where userid=4;
#5,不支持对任意基表的删除操作
delete from `hjtest`.`user_oppo` where userid=11 ;