In previous articles, Mytour introduced you to SQL commands, including CREATE, DELETE, INSERT, etc. In this article, Mytour continues to introduce you to VIEWs in SQL.
VIEW (visual representation) in SQL is stored as a SELECT statement in the database. DML operations in VIEW, such as INSERT, UPDATE, DELETE, affect the data in the original table.
Syntax for Creating SQL VIEWs
The syntax for creating a VIEW in SQL is as follows:
CREATE VIEW view_name
AS
SELECT column_list
FROM table_name [WHERE condition];
Where:
- view_name is the name of the VIEW.
- The SELECT statement is utilized to specify the columns and rows you wish to display in the VIEW.
Example of VIEW in SQL
To create a VIEW in the product table, the SQL query is written as follows:
CREATE VIEW view_product
AS
SELECT product_id, product_name
FROM product;
Here are the details about VIEWs in SQL. In addition to the basic commands introduced by Mytour earlier, for a deeper understanding of commands related to granting and revoking privileges, access rights in SQL, or other commands like Index in SQL for data deletion, readers can explore the latest SQL articles on Mytour.
