Mysql views & Business & Triggers

Reference material

A view

View meanings:

A view is a virtual table, or a plurality of tables is lead out from the database table.

1, create a view

 

# Syntax: CREATE VIEW view name AS SQL statement to 
the Create View teacher_view the SELECT tid AS from Teacher tname the WHERE = ' Li Ping teacher ' ; 

# then query sql courses name of Professor Li Ping teacher can be rewritten as 
MySQL> the SELECT CNAME from Course, the WHERE teacher_id = (SELECT TID from teacher_view);
 + -------- + 
| CNAME | 
+ -------- + 
| physical | 
| art | 
+ -------- + 
rows in SET (0.00 sec) 

# ! ! ! Note Note Note: 
# 1. After using the view there is no need to rewrite every sub-query sql, but efficiency is not so high, not high as we write efficiency subquery 

# 2 and there is a fatal problem: the view is stored in the database, and if we over-reliance program sql stored in the database view,
It means that, once the need to modify the sql view and relate to the part, you must make changes to the database, but usually have a dedicated DBA is responsible for the database in the company, 
you want to complete the changes, it takes a lot of communication costs may only DBA We will help you complete the changes, extremely inconvenient

2, view view

select * from course_view;

 

 

 

Guess you like

Origin www.cnblogs.com/foremostxl/p/11409499.html