What is a VIEW ?
What is a VIEW ?
A view in SQL is a virtual table that is created based on the result set of an SQL query. Unlike a table, a view does not store data physically in the database. Instead, it dynamically retrieves data from one or more underlying tables whenever it is queried. Here are some key points about views:
Definition: A view is essentially a saved SQL query that can be treated as a table. It contains rows and columns just like a real table, but the data is derived from the underlying base tables each time the view is accessed[1][2][4].
Creation: Views are created using the CREATE VIEW
statement. The syntax typically looks like this:
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
For example, to create a view that shows all customers from Brazil, you would use:
CREATE VIEW Brazil_Customers AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = 'Brazil';
```[4][11].
Usage: Views can be used to simplify complex queries, provide a layer of security by restricting access to specific data, and present data in a specific format without altering the underlying tables. They can also be used to join data from multiple tables, aggregate data, and hide the complexity of the database schema from the end-users[1][2][5][9].
Advantages:
Limitations:
entry
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào