• Learning MySQL By Example
  • Introduction
  • 1. How to Retrieve Data From a Single Table
  • 2. How to Retrieve Data from Multiple Tables
  • 3. Using Functions
  • 4. How to Insert, Update, Delete Data in Tables
  • 5. Summary Queries and Aggregate Functions
  • 6. Working With Subqueries
  • 7. SQL Views
  • 8. SQL Indexes
  • Glossary
  • Index
  • Download
  • Translations
  • 7.2

    Benefits of Using Views

    Benefits of Using Views

    • Design Flexibility: By using a view instead of a query in an application, it is easier to make changes to the underlying table structure.
    • Improved Security: By using a view to return data from tables instead of a SELECT, you can hide the WHERE clause or other columns to which you do not want the user to have access.
    • Query Simplification: You can write simple select statements against views, which handle complex queries and joins.

    Code Sample:

    USE WORLD;
    CREATE VIEW city_country AS
    SELECT ci.name AS city_name, co.name AS country_name
    FROM city ci
        JOIN country co
        ON ci.CountryCode = co.Code;

    Results by selecting from the city_country view:

    v_01.png

    CREATE VIEW city_country AS


    SELECT ci.name AS city_name, co.name AS country_name

    FROM city ci

         JOIN country co

        ON ci.CountryCode = co.Code;

    This content is provided to you freely by EdTech Books.

    Access it online or download it at https://edtechbooks.org/learning_mysql/benefits_of_using_vi.