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

View

A view is a stored SQL statement that acts as a virtual table, allowing users to structure, restrict access, and summarize data from one or more tables. Views can simplify complex queries, enhance data security, and provide data abstraction, but they also have disadvantages such as update restrictions and potential performance issues. The basic syntax for creating a view involves the CREATE VIEW statement followed by a SELECT query.

Uploaded by

swatisingh5874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

View

A view is a stored SQL statement that acts as a virtual table, allowing users to structure, restrict access, and summarize data from one or more tables. Views can simplify complex queries, enhance data security, and provide data abstraction, but they also have disadvantages such as update restrictions and potential performance issues. The basic syntax for creating a view involves the CREATE VIEW statement followed by a SELECT query.

Uploaded by

swatisingh5874
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

View

A view is nothing more than a SQL statement that is stored in the database with an associated
name. A view is actually a composition of a table in the form of a predefined SQL query.A view
can contain all rows of a table or select rows from a table. A view can be created from one or
many tables which depends on the written SQL query to create a view.

Views, which are a type of virtual tables allow users to do the following –

 Structure data in a way that users or classes of users find natural or intuitive.
 Restrict access to the data in such a way that a user can see and (sometimes) modify
exactly what they need and no more.
 Summarize data from various tables which can be used to generate reports

Creating Views
 Database views are created using the CREATE VIEW statement. Views can be created
from a single table, multiple tables or another view.
 To create a view, a user must have the appropriate system privilege according to the
specific implementation.

 The basic CREATE VIEW syntax is as follows −


CREATE VIEW view_name AS
 SELECT column1, column2.....
 FROM table_name
 WHERE [condition];

Example

Consider the CUSTOMERS table having the following records.


Following is an example to create a view from the CUSTOMERS table. This view would be
used to have customer name and age from the CUSTOMERS table
SQL > CREATE VIEW CUSTOMERS_VIEW AS
SELECT name, age
FROM CUSTOMERS;

Now, you can query CUSTOMERS_VIEW in a similar way as you query an actual table.
Following is an example for the same
SQL > SELECT * FROM CUSTOMERS_VIEW;

Uses of a View :
A good database should contain views due to the given reasons:
1. Restricting data access – Views provide an additional level of table security by restricting
access to a predetermined set of rows and columns of a table.
2. Hiding data complexity – A view can hide the complexity that exists in a multiple table join.
3. Simplify commands for the user – Views allows the user to select information from multiple
tables without requiring the users to actually know how to perform a join.
4. Store complex queries – Views can be used to store complex queries.
5. Rename Columns – Views can also be used to rename the columns without affecting the base
tables provided the number of columns in view must match the number of columns specified in
select statement. Thus, renaming helps to to hide the names of the columns of the base tables.
6. Multiple view facility – Different views can be created on the same table for different users.

Advantages of Views
1. Simplification of Complex Queries: By combining complex queries into a single,
reusable item, views make them easier to understand. You can make a view and refer to it
as a table rather than recreating a long query with numerous joins or computations.
2. Enhanced Data Security: Views restrict access to sensitive information by exposing
only specific columns or rows. Users accessing a view cannot see the underlying tables,
ensuring data privacy and security
3. Reusability: You can reuse a query in several reports, analytics, and apps by designating
it as a view. This lessens query logic duplication and encourages consistency
4. Data Abstraction: Views shield users from the intricacy of the database schema. It is
possible to update the view without impacting dependent queries or applications in the
event that the schema of the underlying tables changes.
5. Improved Performance with Materialized Views: Materialized views are used in
certain database systems (like Oracle and PostgreSQL) to physically store query results,
which enhances performance for data that is requested frequently.
Or
 Data independence– presents a consistent, unchanging picture of the database's structure
even when the source tables change
 Currency– changes to the base tables are reflected immediately in the views.
 Improved security- users can be granted access to the database through a relatively small
set of views.
 Reduced complexity–simplifies the writing of queries.
 Convenience–users see only what they need.
 Customization–views can be customized to the needs of individual users.
 Data integrity–CHECKOPTION clause of the CREATE VIEW command ensures that
rows satisfy the WHERE clause of the defining query
Disadvantages of Views
 Update restriction– in some cases (aswe saw),a view might not be updated.
 Structure restriction– Structure is determined at the time of creation. Any columns added
to the database will not show up unless the view is dropped and redefined.
 Performance–The use of view slows down response time in some cases.

You might also like