How to Create MySQL views

Spread the love

MySQL has bolstered database sees since rendition 5.x. Perspectives are quite helpful in the event that you need to allude to values computed from expressions without composing the expressions each time you can recover them.

What is a view

A view is only a picture table or virtual table, which contains no information, which is crated for a base table. A view can be made by taking all qualities from the base table or by taking just chose values from base table.

How to access view contents

To access the view contents, refer to it like any other table. you can select some or all of its columns, add a where clause to restrict which rows to retrieve, use order by to sort rows and so forth.

View data update

If we perform any modifications in base table, then those modifications automatically effected in view and vice versa.

Creating views

The CREATE VIEW statement creates a new view, or replaces an existing view if the OR REPLACE clause is given. If the view does not exist, CREATE OR REPLACE VIEW is the same as CREATE VIEW. If the view does exist, CREATE OR REPLACE VIEW is the same as ALTER VIEW.

MySQL allows you to create a view based on other views. In the SELECT statement of the view definition, you can refer to another view.

Syntax to create view:

Syntax to drop the view:

You cannot create an index on a view. MySQL uses indexes of the underlying tables when you query data against the views that use the merge algorithm. For the views that use the temptable algorithm, indexes are not utilized when you query data against the views.

Leave a Reply

Your email address will not be published. Required fields are marked *