SQL VIEWS

A view is a virtual table.

SQL CREATE VIEW

A view is a virtual table based on the result of a query (SELECT) to a table.

CREATE VIEW AS viewName SELECT columnName (s) FROM tableName WHERE condition

The view always show actual data from one or more tables.

Each time a user question and a view, the system database, updates the view to always display actual data.

Example SQL CREATE VIEW

In the table people

namesurnamenicknameage
HARRYCLARKWHITE30
HARRYSMITHJOHNSON45
JOHNBROWNANDERSON50

We create a view with the people who call Harry

CREATE VIEW [people who call Harry] AS SELECT name, surname, nickname, age FROM people WHERE name = 'HARRY'

For data in a view

SELECT * FROM [people called HARRY]

At the hearing [people called HARRY] we have the following data:

namesurnamenicknameage
HARRYCLARKWHITE30
HARRYSMITHJOHNSON45

SQL REPLACE VIEW

To replace or modify data in a view:

REPLACE VIEW [people called HARRY] AS SELECT name, surname, nickname, age FROM people WHERE age > 20

SQL DROP VIEW

To delete a view

DROP VIEW viewName

Example Removal seen before created

DROP VIEW [people called HARRY]