SQL views are virtual tables with rows and columns, just like actual tables in a database. To create a view, you have to select fields from tables that exist in the database.
Contents
SQL VIEW: Main Tips
- View in SQL means virtual tables made of a result-set.
- An SQL view has columns and rows.
- You can use WHERE and JOIN statements to show the information as if it was being received from a single table.
SQL VIEW Syntax and Examples
CREATE VIEW v_name AS
SELECT col1, col2, ...
FROM tbl_name
WHERE condition;
Note: VIEW only displays the present information.
Every one of the active cells that are inside Products table is listed in the Present List Products view:
CREATE VIEW [Present List Products] AS
SELECT ID, Name
FROM Products
WHERE Discontinued = No;
The example below shows how to query a view:
SELECT * FROM [Present List Products];
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified certificates of completion
Updating the VIEW
The syntax example below shows how to update your view:
CREATE OR REPLACE VIEW v_name AS
SELECT col1, col2, ...
FROM tbl_name
WHERE condition;
The next step to finish updating the view is to insert one more column called Category:
CREATE OR REPLACE VIEW [Present List Products] AS
SELECT ID, Name, Category
FROM Products
WHERE Discontinued = No;
Dropping the VIEW
To remove a view use DROP VIEW:
DROP VIEW v_name;
SQL VIEW: Summary
- Virtual tables that are made of a result-set of an actual table(s) in a database are called SQL views.
- WHERE and JOIN statements used on views return the information as if it was stored in a single table.