SQL: EXTRA - VIEWS

VUEWS

A view is a database object that is of stored query. Simplify the complexity of a query.

Syntax:

-- VIEW 
CREATE VIEW view_name AS query

Example: VIEW

-- View
CREATE VIEW customer_info AS 
SELECT first_name, last_name, email, address, phone
FROM customer
JOIN address
ON customer.address_id = address.address_id;
## data frame with 0 columns and 0 rows
-- View
SELECT * FROM customer_info
limit 20;
## NULL

Example: Rename customer_info to customer_master_list

-- ALTER VIEW
ALTER VIEW customer_info RENAME TO customer_master_list;
## data frame with 0 columns and 0 rows
-- SELECT
SELECT * FROM customer_master_list
limit 20;
## NULL

Example: DROP VIEW

-- DROP VIEW
DROP VIEW customer_master_list;
## data frame with 0 columns and 0 rows
-- SELECT
SELECT * FROM customer_master_list
limit 20;
## NULL