unit 2
unit 2
A view looks and acts a lot like a table. It has columns and rows, and can be
included in SELECT queries just like a table.
If you look at a SELECT query that uses a view, sometimes you might not
know that you are querying from a view. The name of the object being
queried from could represent a table or a view (or a synonym!).
One thing to remember is that the view object is only a stored SQL query.
This means that no data is stored along with the view. The view object only
stores your SQL query, and whenever you query the view, it runs the query
that is stored against it.
There are several reasons to use views in SQL. This applies to any SQL
variation you use (Oracle, SQL Server, MySQL, etc).
Simplify Queries
The main advantage to using views is that they simplify your queries.
For example, you can create a view that counts the number of orders and
totals the order volume for all orders for each month. You can then query this
view and limit by month to find the data you need for a specific month.
Security
Another benefit of using views is increased security. You can create a view
that only selects certain columns from a table. Then, certain users, or
applications, can be given access to this view rather than the entire table.
For example, you may have an employee table with salary information. You
might not want all applications or users to see this salary information.
So, you can create a view that selects all columns except for the salary
columns, and then give access to that view to other users (and don’t give
them access to the employee table).
This means when they query the employee view, they won’t see the salary
information.