0% found this document useful (0 votes)
23 views10 pages

10 Views

Views allow presenting subsets of data from tables without storing duplicate data. Views can restrict access, simplify complex queries, provide independence from base tables, and present different views of the same data. Synonyms provide alternative names for objects like tables and views to simplify access.

Uploaded by

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

10 Views

Views allow presenting subsets of data from tables without storing duplicate data. Views can restrict access, simplify complex queries, provide independence from base tables, and present different views of the same data. Synonyms provide alternative names for objects like tables and views to simplify access.

Uploaded by

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

Views

1
What Is a View?
You can present logical subsets or combinations of data by creating views of tables. A
view is a logical table based on a table or another view. A view contains no data of its
own but is like a window through which data from tables can be viewed or changed.
The tables on which a view is based are called base tables. The view is stored as a
SELECT statement in the data dictionary.

EMPLOYEES table
Advantages of Views
To restrict To make complex
data access queries easy

To provide data To present different


independence views of the same
data
Advantages of Views

• Views restrict access to the data because the view can display
selected columns from the table.

• Views can be used to make simple queries to retrieve the results of


complicated queries.

• Views provide data independence .One view can be used to retrieve


data from several tables.

• Views provide groups of users access to data according to their


particular criteria.
Creating a View

Create the EMPVU80 view, which contains


details of employees in department 80:

CREATE VIEW empvu80


AS SELECT employee_id, last_name, salary
FROM employees
WHERE department_id = 80;
View created.
Creating a View
– Create a view by using column aliases in the subquery:

CREATE VIEW salvu50


AS SELECT employee_id ID_NUMBER, last_name NAME,
salary*12 ANN_SALARY
FROM employees
WHERE department_id = 50;
View created.
– Select the columns from this view by the given alias
names:
Retrieving Data from a View
SELECT *
FROM salvu50;
Removing a View
• You can remove a view without losing data because a view is
based on underlying tables in the database.
DROP VIEW view;

DROP VIEW empvu80;


View dropped.
Synonyms
• Simplify access to objects by creating a synonym
(another name for an object). With synonyms, you can:
– Create an easier reference to a table, view or table
– Shorten lengthy object names

CREATE [PUBLIC] SYNONYM synonym


FOR object;
Creating and Removing Synonyms
– Create a shortened name for the DEPT_SUM view:

CREATE SYNONYM d_sum


FOR dept_sum;
Synonym Created.

– Drop a synonym:
DROP SYNONYM d_sum;
Synonym dropped.

You might also like