MySQL View


Views are virtual tables what consist of columns and rows from real tables within a database. Views don’t contain the data they display. Views are practically for read-only but some databases allow updating on views.

Here is how you create a view.

CREATE VIEW view_name AS
SELECT column_name1, column_name2, ...
FROM table_name
WHERE condition;

You can just JOINs if needed to generate your SELECT statement. Here is how views are created.

Advantages of Views

  1. A database view simplifies the complexity of a query. The underlying view might consist of a complex query like multiple joins and subqueries so calling a view by a simple select statement really helps reduce the code you have to write.
  2. A database view can have calculated columns.
  3. A database view can be created based off of another view.

Disadvantages of Views

  1. Table dependency.
  2. Slowness in performance if views are derived from other views.
  3. Views cannot have indexes. Only the underlying tables have indexes.
  4. If you rename a column name on the underlying table, MySQL does not throw an exception.
  5. Views based on complex queries such as JOINs and sub queries are not updatable. Simple select statement views are updatable.

Views and tables share the same namespace so views cannot be named the same name of an existing table.



Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!


Leave a Reply

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