/    /  MySQL – Views

MySQL – Views

 

MySQL – Views

A view is a database object that does not contain any values. Based on the base table, its contents are determined. There are rows and columns that are similar to those in the real table. A view in MySQL is a virtual table that is created as a result of joining several tables together. In contrast to the base table, it does not contain any data of its own. There is one main difference between a view and a table, namely that views are defined on top of other tables. The same changes that occur in the underlying table will also appear in the view.

Advantages of MySQL Views

1) Simplify complex query

It is possible to simplify complex queries by using views. Whenever you perform a complex query frequently, you should create a view based on it. This is so that you can refer to it via a simple SELECT statement instead of retyping the query.

2) Make the business logic consistent

Suppose you have to repeat the same formula in each query. Alternatively, you may have a query that has complex business logic. In order to make this logic consistent across queries, you can use a view to store the calculations and hide the complexities associated with them.

3) Add extra security layers

It is possible that a table may be exposed to a lot of data, including sensitive information such as personal and financial information.

It is possible to limit which data users can access by using views and privileges. These tools let you expose only the data that is necessary for them.

4) Enable backward compatibility

It is possible to achieve backward compatibility with legacy systems using views.

The purpose of normalization is to reduce the size of a large table into many smaller ones. Furthermore, you do not want to affect existing applications that reference the table.

To make all applications refer to the view as if it was a table, you can create a view with the same name as the table based on the newly created table.

The name of a view and table cannot be the same, so you must drop the table before creating a view with the same name.