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 BYU-I Books.

Access it online or download it at https://books.byui.edu/learning_mysql/benefits_of_using_vi.