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

Experiment-11 AIM - Introduction To Views. VIEWS A View Is, in Essence, A Virtual Table. It Does Not Physically Exist. Rather, It Is Created

Views are virtual tables that are dynamically generated from the data in one or more real database tables. Views allow users to present data from tables in a customized way without altering the structure of the underlying tables. Views can filter columns and rows from tables, join multiple tables, and perform aggregations. Views provide benefits like security, abstraction, and ease of use when querying data. Operations on views include creating, replacing, inserting, deleting, and dropping views.

Uploaded by

abhinavmehan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Experiment-11 AIM - Introduction To Views. VIEWS A View Is, in Essence, A Virtual Table. It Does Not Physically Exist. Rather, It Is Created

Views are virtual tables that are dynamically generated from the data in one or more real database tables. Views allow users to present data from tables in a customized way without altering the structure of the underlying tables. Views can filter columns and rows from tables, join multiple tables, and perform aggregations. Views provide benefits like security, abstraction, and ease of use when querying data. Operations on views include creating, replacing, inserting, deleting, and dropping views.

Uploaded by

abhinavmehan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

EXPERIMENT-11

AIM – Introduction To Views.


VIEWS A view is, in essence, a virtual table. It does not physically exist. Rather, it is created
by a query joining one or more tables. In SQL, a view is a virtual table based on the result-set of
an SQL statement. Essentially a view is very close to a real database table (it has columns and
rows just like a regular table), except for the fact that the real tables store data, while the views
don’t. A view contains rows and columns, just like a real table. The fields in a view are fields
from one or more real tables in the database. The view’s data is generated dynamically when the
view is referenced. A view references one or more existing database tables or other views. In
effect every view is a filter of the table data referenced in it and this filter can restrict both the
columns and the rows of the referenced tables.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if
the data were coming from one single table. Changing the data in a table alters the data shown in
subsequent invocations of the view. The syntax of the view command is

CREATE OR REPLACE VIEW <viewname> AS


SELECT <col1>,<col2>
FROM <tablename>
WHERE condition
GROUPBY<grouping criteria>
HAVING <predicate>;

PURPOSE OF VIEWS Views are used to select particular columns from a table which is
residing in a different DB. Thus it serves as a security mechanism. Once views are created we
can access the view to get the specified column details from the table which is present in a
different DB. Sometimes we need to use the same query repeatedly for a large number of times.
So instead of writing the same query all the times we use views. Using view we can avoid the
complex queries.

FUNCTIONS OF VIEWS
 Views can subset data in a table
 They can join multiple tables into one virtual table
 They can act as aggregated tables. i.e. a view can be used to store Sum, average of values
 Views can be nested and can be used for abstraction
 Views can provide security and decrease complexity
 They save space because only their definition is stored.
 Materialized views are commonly used in data warehousing. They represent a snapshot
of the data from remote sources.

Just as functions (in programming) can provide abstraction, so database users can create
abstraction by using views. In another parallel with functions, database users can manipulate
nested views, thus one view can aggregate data from other views. Without the use of views the
normalization of databases above second normal form would become much more difficult.
Views can make it easier to create lossless join decomposition.
A view is a relational table, and the relational model defines a table as a set of rows. Since sets
are not ordered - by definition - the rows in a view are not ordered, either. Therefore, an ORDER
BY clause in the view definition is meaningless. The SQL standard does not allow an ORDER
BY clause in a subselect in a CREATE VIEW statement, just as it is not allowed in a CREATE
TABLE statement. However, sorted data can be obtained from a view, in the same way as any
other table - as part of a query statement.

RESTRICTIONS IMPOSED OVER VIEWS


 A view can be created only in the current database.
 The name of a view must follow the rules for identifiers and must not be the same as that
of the base table.
 A view can be created only if there is a SELECT permission on its base table.
 A SELECT INTO statement cannot be used in view declaration statement.
 A trigger or an index cannot be defined on a view.
 The CREATE VIEW statement cannot be combined with other SQL statements in a
single batch.

VIEWS CAN PROVIDE ADVANTAGES OVER TABLES


 Views can represent a subset of the data contained in a table
 Views can join and simplify multiple tables into a single virtual table
 Views can act as aggregated tables, where the database engine aggregates data (sum,
average etc.) and presents the calculated results as part of the data
 Views can hide the complexity of data
 Views take very little space to store; the database contains only the definition of a view,
not a copy of all the data it presents
 Depending on the SQL engine used, views can provide extra security
 Views can limit the degree of exposure of a table or tables to the outer world
 Views take very little space to store, since they do not store actual data.
 Views can include only certain columns in the table so that only the non-sensitive
columns are included and exposed to the end user. In addition, some databases allow
views to have different security settings, thus hiding sensitive data from prying eyes.

OPERATIONS ON VIEWS
 Creating A View

 Replace An Existing View


 Inserting Values In A View

 Inserting Values In A View Where Condition Does Not Satisfy

It does not show the row 1010. Because extmarks is not according to WHERE condition.
 Creating A view Using CHECK OPTION
 Insertion When CHECK OPTION is Used But Does Not Match The WHERE condition

 Deleting A Row In A View

Dropping A View

 Deleting All Rows In A View


 Creating View Using Group By Expression

 Creating View Using Group By Expression And Having Condition

Creating Views Using Joins


 Equi-Join

 Outer-Join
 Cartesian-Join

 Self Join

You might also like