視圖是一種虛擬存在的表,行和列的數據來自於定義的視圖的查詢中使用的表,而且是在使用視圖中動態生成的,只保存sql邏輯,不保存數據sql
#語法結構 create view 視圖名 as 查詢語句 create view my_view as select s.name as student_name,c.name as class_name from student s join class c on s.classid = c.id; #查看視圖 此時視圖裏只有兩個字段 desc my_view; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | student_name | varchar(20) | NO | | NULL | | | class_name | varchar(20) | NO | | NULL | | +--------------+-------------+------+-----+---------+-------+
#注意:查詢時只能夠使用視圖中的字段進行查詢 select * from my_view where student_name = '張三';
有兩種方式修改視圖函數
方式一:有則修改,沒有則建立code
create or replace view 視圖名 as 查詢語句
方式二:get
alter view 視圖名 as 查詢語句
drop view 視圖名,視圖名,...
在使用簡單地查詢語句做爲視圖時,能夠對視圖進行增刪改操做,並且對視圖的操做也會一樣使數據表完成相應的變化博客
可是包含如下特色的視圖不容許更新io
因爲自己的博客百度沒有收錄,博客地址http://zhhll.icuclass