

Create views – show you how to use the CREATE VIEW statement to create a new view in the database.Note that a view and table cannot have the same name so you need to drop the table first before creating a view whose name is the same as the deleted table. In this case, you can create a view whose name is the same as the table based on the new tables so that all applications can reference the view as if it were a table. And you don’t want to impact the current applications that reference the table.

Suppose, you want to normalize a big table into many smaller ones.

In legacy systems, views can enable backward compatibility. To expose general information such as first name, last name, and gender to the General Administration (GA) department, you can create a view based on these columns and grant the users of the GA department to the view, not the entire table employees. 3) Add extra security layersĪ table may expose a lot of data including sensitive data such as personal and banking information.īy using views and privileges, you can limit which data users can access by exposing only the necessary data to them.įor example, the table employees may contain SSN and address information, which should be accessible by the HR department only. To make this logic consistent across queries, you can use a view to store the calculation and hide the complexity. Or you have a query that has complex business logic. Suppose you have to repeatedly write the same formula in every query. If you have any frequently used complex query, you can create a view based on it so that you can reference to the view by using a simple SELECT statement instead of typing the query all over again. MySQL views bring the following advantages. This picture shows the output: Advantages of MySQL Views Code language: SQL (Structured Query Language) ( sql )
