Mysql 视图创建

  1. 创建单表视图
create view view_name as 
select column1,column1,column1 from table1;
  1. 定义列名(定义或隐藏表结构)
create view view_name(vc1,vc2,vc3) as select c1,c2,c3 from tab1;
  1. 创建多表视图
create view view_name(id,name,price) as 
select ta.id,ta.name,tb.price from ta,tb where ta.id=tb.id'

查看视图结构
describe view_name

查看视图信息
show tables status like ‘view_’ \G;

**查看视图详细信息
show create view view_name \G;**

查看views表中的视图详细信息(查看全部视图信息)
select * from information_schema.views;

  1. 修改视图
create or replace view view_name as select * from t;
alter view view_name as select * from t;
  1. 更新视图
update view_name set id=1;
  1. 视图删除信息
delete from view_name where price=5;

4.移除视图

Drop view if exists view_name;

你可能感兴趣的:(MySQL,视图,MySQL)