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

Lesson 12: Creating Other Schema Objects

The document discusses views, indexes, and other Oracle database objects. It defines a view as a logical table based on one or more underlying tables or other views. Views allow for data presentation and restriction without storing data. Indexes are defined as structures that allow for faster data retrieval and can be unique or non-unique. The document provides examples of creating views with the CREATE VIEW statement and creating indexes with the CREATE INDEX statement. It also discusses describing views, viewing definitions in data dictionaries, and removing indexes.

Uploaded by

Tayyab Murad
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)
28 views

Lesson 12: Creating Other Schema Objects

The document discusses views, indexes, and other Oracle database objects. It defines a view as a logical table based on one or more underlying tables or other views. Views allow for data presentation and restriction without storing data. Indexes are defined as structures that allow for faster data retrieval and can be unique or non-unique. The document provides examples of creating views with the CREATE VIEW statement and creating indexes with the CREATE INDEX statement. It also discusses describing views, viewing definitions in data dictionaries, and removing indexes.

Uploaded by

Tayyab Murad
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/ 36

LESSON 12

Creating Other
Schema Objects
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
What is a View?
 You can present logical subsets or combination 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.

DBT BSSE-A-F12
DBT BSSE-A-F12
WHY USE VIEWS:

 To restrict database access.


 To make complex queries easy.
 To allow data independence. (one view can be used to retrieve data from
several tables.)
 To present different views of the same data.

Types of views:

i) Simple View:
 Derives data from only one table.
 Contains no functions or groups of data.
 Can perform DML through the view.
ii) Complex View:
 Derives data from many tables.
 Contains functions or groups of data.
 Does not always allow DML through view.

DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
CREATE VIEW :

 Syntax:
CREATE VIEW <views name>
AS
<select query>;

 Example:
CREATE VIEW emp01
AS
SELECT empno, ename FROM emp WHERE deptno = 10;

DESCRIBE VIEW:

Describe the structure of the view by using the SQL * PLUS


DESCRIBE Command.

DESCRIBE emp01;

DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
Views in the Data Dictionary:

 Once your view has been created, you can query the data
dictionary view called USER_VIEWS to see the name of the
view and the view definition.

Example:

select view_name, text


from user_views
where upper(view_name) = 'EMP_VIEW'

DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
CREATING INDEX:

Syntax:
 CREATE INDEX <index_name>
ON TABLE (column, column, ……..)

Example of Non-Unique Index:


CREATE INDEX emp_ename_idx
ON emp(ename);

Example of Unique Index:


CREATE UNIQUE INDEX unique_ind
ON dummy(empno);

REMOVING AN INDEX:
Remove an index from the data dictionary.
DROP INDEX <index_name>;
ALTERING TABLE:
ALTER TABLE sales ADD CONSTRAINT sales_unique UNIQUE
(sales_id)DISABLE VALIDATE; DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12
DBT BSSE-A-F12

You might also like