What do you mean by database view and how do MySQL views work?

A database view is nothing more than an SQL statement that is stored in the database with an associated name. A view is actually a composition of a table in the form of a predefined SQL query.

A view can contain all rows of a table or select rows from a table. A MySQL view can be created from one or many tables which depend on the written MySQL query to create a view.

Views, which are a type of virtual tables allow users to do the following −

  • Structure data in a way that users or classes of users find natural or intuitive.
  •  Restrict access to the data in such a way that a user can see and (sometimes) modify exactly what they need and no more.
  •  Summarize data from various tables that can be used to generate reports.

Basically, views are definitions built on the top of other tables of views. If data is changed in the underlying table, the same is reflected in the view. A view can be built on top of single or multiple tables. MySQL supported databases views since version 5+ and process the queries against views in the following two ways −

  • By creating a temporary table − In this way, MySQL creates a temporary table based on the view definition statement and executes the incoming query on this temporary table.
  •  By combining the queries −In this way, MySQL combines the incoming query with the query defined the view into one query and executes the combined query.

Updated on: 22-Jun-2020


Kickstart Your Career

Get certified by completing the course

Get Started