Sie sind auf Seite 1von 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

Das könnte Ihnen auch gefallen