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

Virtual Table - Simple View - Complex View - Advantage: Document Prepared by

The document discusses different types of views in a database: simple views which show data from a single table, and complex views which show data from multiple tables and can use functions. It provides examples of creating a complex view, updating the view definition, and dropping a view. Views allow restricting and simplifying access to base table data, and different views can represent the same data in different ways.

Uploaded by

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

Virtual Table - Simple View - Complex View - Advantage: Document Prepared by

The document discusses different types of views in a database: simple views which show data from a single table, and complex views which show data from multiple tables and can use functions. It provides examples of creating a complex view, updating the view definition, and dropping a view. Views allow restricting and simplifying access to base table data, and different views can represent the same data in different ways.

Uploaded by

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

VIEW

VIRTUAL TABLE SIMPLE VIEW COMPLEX VIEW - ADVANTAGE


CREATE UPDATE DROP

Document prepared by: AN.Murugappan

VIEW
IT IS A LOGIGAL REPRESENTETION OF SUBSET OF DATA FROM ONE OR MORE TABLE IT CAN NOT CONTAIN DATA OF ITS OWN BUT IT IS ACT AS WINDOW TO ACCESS THE DATA FROM THE BASE TASE TABLES. IT CAN BE VIEWED OR CHANGED.

DIFFERENCE BETWEEN SIMPLE VIEW AND COMPLEX VIEW SIMPLE VIEW COMPLEX VIEW

DATA FROM SINGLE TABLE HERE WE CANT USE GROUP FUNCTIONS (e.g. min, max, sum etc..,)

DATA FROM ONE OR MORE TABLE

HERE WE CAN USE IT

YOU CAN PERFORM DML STATEMENT HERE

YOU CANT PERFORM DML STATEMENT HERE

OPERATIONS ON VIEW: Create Update Drop

CREATING A VIEW: COMPLEX QUERY:

SELECT E.EMPLOYEE_ID, E.FIRST_NAME, E.SALARY, E.DEPARTMENT_ID, D.DEPARTMENT_NAME, D.LOCATION_ID, L.CITY FROM EMPLOYEES E, LOCATIONS L, DEPARTMENTS D WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID AND D.LOCATION_ID = L.LOCATION_ID AND (E.EMPLOYEE_ID BETWEEN 100 AND 107);

SYNTAX FOR CREATING A VIEW CREATE VIEW VIEW_NAME AS [SIMPLE OR COMPLEX QUERY]

EXAMPLE: CREATING QUERY FOR ABOVE COMPLEX QUERY

CREATE VIEW EMP_DETAILS AS SELECT E.EMPLOYEE_ID, E.FIRST_NAME, E.SALARY, E.DEPARTMENT_ID, D.DEPARTMENT_NAME, D.LOCATION_ID,L.CITY FROM EMPLOYEES E,LOCATIONS L, DEPARTMENTS D WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID AND D.LOCATION_ID = L.LOCATION_ID AND (E.EMPLOYEE_ID BETWEEN 100 AND 107);

SELECT * FROM EMP_DETAILS;

Updating a VIEW

SYNTAX FOR CREATING A VIEW CREATE OR REPLACE VIEW VIEW_NAME AS [SIMPLE OR COMPLEX QUERY]

HERE WE UPDATE THE CREATED VIEW BY CHANGING ITS RANGE IN THE WHERE CLAUS

CREATE OR REPLACE VIEW EMP_DETAILS AS SELECT E.EMPLOYEE_ID, E.FIRST_NAME, E.SALARY, E.DEPARTMENT_ID, D.DEPARTMENT_NAME, D.LOCATION_ID,L.CITY FROM EMPLOYEES E, LOCATIONS L, DEPARTMENTS D WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID

AND D.LOCATION_ID = L.LOCATION_ID AND (E.EMPLOYEE_ID BETWEEN 107 AND 109);

SELECT * FROM EMP_DETAILS;

DROP A VIEW: SYNTAX FOR DROP A VIEW DROP VIEW VIEW_NAME;

DROP VIEW EMP_DETAILS;

ADVANTAGE: 1. To restrict the data access 2. To make the complex query easy 3. We can provide different view for the same data.

We can perform dml (insert, update, delete, and merge) operations on the simple view If you insert one row of record into view means it will inserted in to base table If you insert the selected no of columns means remaining values are inserted as null (if it is not set as primary key, not null and unique identifier)

CREATE OR REPLACE VIEW VIEW_NAME AS [SIMPLE OR COMPLEX QUERY] WITH READ ONLY; If you create a view with this keyword means the user cant have any chance to perform any operation on that.

You might also like