0% found this document useful (0 votes)
6 views

unit 2

A view in SQL is a stored SQL statement that acts like a table, allowing users to simplify complex queries and enhance security by restricting access to specific data. Views can include various SQL elements such as joins, functions, and conditions, making it easier to manage and reuse query logic. By using views, sensitive information can be hidden while still providing necessary data access to users or applications.

Uploaded by

Sushma Borkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

unit 2

A view in SQL is a stored SQL statement that acts like a table, allowing users to simplify complex queries and enhance security by restricting access to specific data. Views can include various SQL elements such as joins, functions, and conditions, making it easier to manage and reuse query logic. By using views, sensitive information can be hidden while still providing necessary data access to users or applications.

Uploaded by

Sushma Borkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

What is a View?

A view is an SQL statement that’s stored in the database. This statement, or


view, has a name.

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.

Why Use a View?


So if a view is just an SQL statement with a name, why would you use one?

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.

As we learned above, views are just stored SQL statements. These


statements can include, for example:
 Selecting of different columns
 Joins to other tables
 Functions, including aggregate functions
 WHERE clauses
 GROUP BY and HAVING
So, if you have a complicated query or logic that’s used in many places, you
can use a view to hold that logic. You can then query from that view
whenever you need that data.

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.

You might also like