MySQL - view

Table of contents

1. View introduction

2. Basic use

3. View rules and restrictions


1. View introduction

A view is a virtual table whose contents are defined by queries. Like a real table, a view contains a series of named columns and rows of data. Data changes in the view will affect the base table, and data changes in the base table will also affect the view .

2. Basic use

Create a view:

create view 视图名 as select语句;

 Case:

It also proves that the view is also a table, and it can also be queried in the data after it is created.

The view is modified, which affects the base table data:

The base table is modified, which affects the view:

Delete a view:

drop view 视图名;

3. View rules and restrictions

  1. Like tables, they must be named uniquely (views or table names with the same name cannot appear)
  2. There is no limit to the number of views created, but the performance impact of creating complex queries as views must be considered.
  3. Views cannot have indexes added, nor can they have associated triggers or default values.
  4. Views can increase security and must have sufficient access rights
  5. order by can be used in a view, but if the data select retrieved from the view also contains order by, the order by in the view will be overwritten.
  6. Views can be used with tables

Guess you like

Origin blog.csdn.net/qq_63943454/article/details/135417594