View and Materialized view. What is a view? Logically represents subset of data from one or more table. In sql, a view is a virtual relation based on.

Slides:



Advertisements
Similar presentations
View (virtual table). View A VIEW is a virtual table A view contains rows and columns, just like a real table. The fields in a view are fields from one.
Advertisements

Basic SQL Introduction Presented by: Madhuri Bhogadi.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Virtual training week 4 structured query language (SQL)
Structure Query Language (SQL) COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Introduction to Structured Query Language (SQL)
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Introduction to Structured Query Language (SQL)
System Administration Accounts privileges, users and roles
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
Introduction to Oracle9i: SQL1 Views. Introduction to Oracle9i: SQL2 Chapter Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
University of Sunderland COM 220Lecture Two Slide 1 Database Theory.
Copyright © 2004, Oracle. All rights reserved. Lecture 3: Creating Other Schema Objects Lecture 3: Creating Other Schema Objects ORACLE.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
1 Information Retrieval and Use (IRU) CE An Introduction To SQL Part 1.
In Oracle.  A PL/SQL block stored in the database and fired in response to a specified event ◦ DML statements : insert, update, delete ◦ DDL statements.
Lecture 8 Creating Stored Functions. Objectives  After completing this lesson, you should be able to do the following:  What is Function?  Types of.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) In some.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Constraints, Triggers and Views COMSATS INSTITUTE OF INFORMATION TECHNOLOGY, VEHARI.
Chapter 2 Views. Objectives ◦ Create simple and complex views ◦ Creating a view with a check constraint ◦ Retrieve data from views ◦ Data manipulation.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Information Building and Retrieval Using MySQL Track 3 : Basic Course in Database.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
Creating Views. 2 home back first prev next last What Will I Learn? List three uses for views from the standpoint of a database administrator Explain,
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
VIEWS A view is like a window through which one can view or change information in the table. Although view does not contain any data of their own. They.
Creating Views Database Systems Objectives Explain the concept of a view. Create simple and complex views. Retrieve data through a view. Alter the.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
SQL Introduction to database and SQL. Chapter 1: Databases and Database Users 6 Introduction to Databases Databases touch all aspects of our lives. Examples:
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
SQL Triggers, Functions & Stored Procedures Programming Operations.
 CONACT UC:  Magnific training   
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
CSED421 Database Systems Lab View. Page 2  Virtual or logical table which is defined as SELECT query with joins  Act as table but not real data, only.
Dr. Chen, Oracle Database System (Oracle) 1 Basic Nested Queries and Views Jason C. H. Chen, Ph.D. Professor of MIS School of Business Gonzaga University.
Other database objects (Sequence and view). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically.
Oracle & SQL Introduction
Creating Views Schedule: Timing Topic 20 minutes Lecture
Basic Nested Queries and Views
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Chapter 2 Views.
“Manipulating Data” Lecture 6.
Database Programming Sections 11 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
“Manipulating Data” Lecture 6.
SQL .. An overview lecture3.
Chapter 2 Views.
Chapter 8 Advanced SQL.
Triggers.
IST 318 Database Administration
Presentation transcript:

View and Materialized view

What is a view? Logically represents subset of data from one or more table. In sql, a view is a virtual relation based on result-set of a SELECT statement. It contains rows and columns just like a real table. Views contains no data of its own but is like a window through which data from table can be viewed or changed. The table on which view a view is based are called BASE TABLE. View is stored as a SELECT statement in the data dictonary. SYNTAX CREATE VIEW view_name AS SELECT column_name(s) FROM table_name WHERE condition;

Advantages of views Views restrict access to data. Views can be used to make simple queries to retrieve the result of complicated queries. Views provide group of users access to data according to their particular criteria.

Types of views Simple views Complex views

Simple views Complex views A simple view is one that :  Derives data from one table.  Contains no functions or group of data.  Can perform DML operations through view. Example: CREATE VIEW emp_view AS SELECT f_name, salary from Employees WHERE dep_id=90; A complex view is one that:  Derives data from many tables.  Contains functions or group of data.  Does not always allow DML operations through view.  In particular, complex views can contain: -join condition -Distinct -Pseudo columns -Group By clause -Having clause Example: CREATE VIEW comp_view AS SELECT e.f_name,e.emp_id,e.job_id,e.dep_id,d.dep _id,d.location WHERE e.dep_id=d.dep_id; Difference between simple and complex views

Creating a view You can create a view by embedding a subquery within the CREATE VIEW statement. The sub query that defines the view can not contain ORDER BY clause. The ORDER BY clause is specified when you retrieve data from the view. Syntax: CREATE OR REPLACE view view_name AS Subquery; In the syntax: OR REPLACE – re_creates the view if its already exists. View _name – name of the view. Subquery - SELECT statement. Eg: CREATE OR REPLACE VIEW emp_view AS SELECT f_name, salary from Employees WHERE dep_id=90; SELECT * FROM emp_view;

View WITH READ ONLY option To restrict the data manipulation using views is done using WITH READ ONLY. CREATE OR REPLACE view v1 AS SELECT A from T1 Where A=1 WITH READ ONLY; Now you perform a DML operation on this view it will throw an error. Eg: INSERT into v1 value(3); Output: ORA-01733: virtual column not allowed here

View WITH CHECK OPTION It specifies that only rows accessible to the view can be inserted or updated. Here WHERE clause will be checked. If WHERE clause does not satisfy error will be thrown Eg: CREATE OR REPLACE view v1 AS SELECT A FROM T1 WHERE A=1 WITH CHECK OPTION; INSERT into v1 values(3); Output: ORA-01402: view WITH CHECK OPTION where-clause violation

View with FORCE option Creates the view regardless of whether or not the base table exist. But we will get error. Eg : CREATE OR REPLACE FORCE view v_new AS SELECT * FROM GREENS; When we execute this particular query view will be created but with error. Output: ORA-00942: table or view does not exist Eg: SELECT * FROM v_new; When we execute this particular view it will throw an error. ORA-04063: view "HR.V1" has errors.

Querying a view 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. The text of the SELECT statement that constitutes your view is stored in a LONG column.

Removing a view You can remove a view without losing data. The DROP statement removes the view definition from the DB. Views based on deleted views become invalid. Only the creator or a user with the DROP ANY VIEW privilege can remove a view. We can remove the error of view by dropping the view or by creating a table. SELECT * FROM USER_ERROR; Syntax Drop view ; Eg: Drop view v_new; View dropped.

Inline views An inline view is a subquery with an alias that you can use within a sql statement. Subquery used in the FROM clause is called inline view. Eg: Select MAX(salary),MIN(salary) FROM (SELECT f_name,salary from emp where d_id=60);

Materialized view It is a snapshot of a remote table data. It is a database object. Data manipulation cannot be done here. The tables in the query are called master tables or detail table. To store a query view is used and to store a result materialized view is used. Sysntax: Create materialized view mv AS SELECT f_name, salary from employees WHERE d_id=90; Select * from mv; When you update a table to refresh the materialized view we use DBMS_MVVIEW.REFRESH(‘mv’,’C’); C means complete refresh. To check all the materialized views created we use SELECT * FROM USER_MVVIEW;

Drop materialized view We can delete a materialized view using syntax DROP MATERIALIZED VIEW ; Eg: Drop materialized view mv;

Difference between normal view and materialized view Normal view It is a stored select statement. It is a virtual component. It allows DESC,DML,SELECT on it. It is stored permanently in “user_views” system table. DML on view are reflected in table and DML on table are reflected in view. It is used to share “selected rows and columns” with other rows. It is used for reporting purpose. It will improve the performance while manipulating or retrieving data through views.

Materialized view It is a static view It holds data in it It will not support DML on it. DML on tale will not reflect in view To create it “create materialized view” permission is required. It is used to maintain historic data. It is used for data analysis and reporting purpose. It is same as SNAP SHOT.