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.

Slides:



Advertisements
Similar presentations
Views-basics 1. 2 Introduction a view is a perspective of the database different users may need to see the database differently; this is achieved through.
Advertisements

A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Introduction to Structured Query Language (SQL)
Data Replication with Materialized Views ISYS 650.
Concepts of Database Management Sixth Edition
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
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.
Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
Introduction to Oracle9i: SQL1 Views. Introduction to Oracle9i: SQL2 Chapter Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE.
MS Access Advanced Instructor: Vicki Weidler Assistant:
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
Chapter 6 Additional Database Objects
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Views: Limiting Access to Data A view is a named select statement that is stored in a database as an object. It allows you to view a subset of rows or.
Database Management. ICT5 Database Administration (DBA) The DBA’s tasks will include the following: 1. The design of the database. After the initial design,
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.
Materialized Views Acknowledgement to Author: Willie Albino.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
Chapter 6 Database Administration
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Triggers. Why Triggers ? Suppose a warehouse wishes to maintain a minimum inventory of each item. Number of items kept in items table Items(name, number,...)
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.
1 Chapter 6 Database Administration. 2 Introduction Database administration The process of managing a database Database administrator A person or an entire.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
Advanced SQL: Triggers & Assertions
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Management Information Systems, 4 th Edition 1 Chapter 8 Data and Knowledge Management.
Visual Programing SQL Overview Section 1.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Chapter 4: SQL Complex Queries Complex Queries Views Views Modification of the Database Modification of the Database Joined Relations Joined Relations.
Indexes and Views Unit 7.
Ing. Erick López Ch. M.R.I. Replicación Oracle. What is Replication  Replication is the process of copying and maintaining schema objects in multiple.
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.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Working with SQL Server Database Objects Faculty: Nguyen Ngoc Tu.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
Indexes- What?  Optional structures associated with tables  Provides a quick access path to table data  You can create indexes on one or more columns.
20 Copyright © 2008, Oracle. All rights reserved. Cache Management.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Description and exemplification use of a Data Dictionary. A data dictionary is a catalogue of all data items in a system. The data dictionary stores details.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
1 Introduction to Database Systems, CS420 SQL Views and Indexes.
SQL Triggers, Functions & Stored Procedures Programming Operations.
 CONACT UC:  Magnific training   
SQL Basics Review Reviewing what we’ve learned so far…….
7.5 Using Stored-Procedure and Triggers NAME MATRIC NUM GROUP Muhammad Azwan Bin Khairul Anwar CS2305A Muhammad Faiz Bin Badrol Shah CS2305B.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Chapter 4 Indexes.
CH 4 Indexes.
Chapter 2 Views.
A Guide to SQL, Eighth Edition
CH 4 Indexes.
Chapter 2 Views.
IST 318 Database Administration
SQL Views Presented by: Dr. Samir Tartir
Presentation transcript:

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 cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) Consider a person who needs to know a customer’s loan number but has no need to see the loan amount. This person should see a relation described, in SQL, by Consider a person who needs to know a customer’s loan number but has no need to see the loan amount. This person should see a relation described, in SQL, by (select customer_name, loan_number from borrower, loan where borrower.loan_number = loan.loan_number ) (select customer_name, loan_number from borrower, loan where borrower.loan_number = loan.loan_number )

A View is a "Virtual Table". It is not like a simple table, but is a virtual table which contains columns and data from different tables (may be one or more tables) A View is a "Virtual Table". It is not like a simple table, but is a virtual table which contains columns and data from different tables (may be one or more tables)

View Definition View is Virtual relation that does not necessarily actually exist in the database but is produced upon request, at time of request. View is Virtual relation that does not necessarily actually exist in the database but is produced upon request, at time of request.

The best view for a particular purpose depends on the information the user needs. The best view for a particular purpose depends on the information the user needs. For example, in a telephone directory, a user might want to look up the name associated with a number, without concern for the street address. The best view for this purpose would have two columns: the phone numbers (in numeric sequence) in the first column, and the name associated with each number For example, in a telephone directory, a user might want to look up the name associated with a number, without concern for the street address. The best view for this purpose would have two columns: the phone numbers (in numeric sequence) in the first column, and the name associated with each number in the second column. Another user might want to look up the phone number associated with a street address, without any need to know the name. The best view for this purpose would have two columns: the street addresses (in alphanumeric order) in the first column, and the phone number in the second column. in the second column. Another user might want to look up the phone number associated with a street address, without any need to know the name. The best view for this purpose would have two columns: the street addresses (in alphanumeric order) in the first column, and the phone number in the second column.

Advantages of views Security Each user can be given permission to access the database only through a small set of views that contain the specific data the user is authorized to see Security Each user can be given permission to access the database only through a small set of views that contain the specific data the user is authorized to see Query Simplicity A view can draw data from several different tables and present it as a single table, turning multi-table queries into single-table queries against the view. Query Simplicity A view can draw data from several different tables and present it as a single table, turning multi-table queries into single-table queries against the view. Structural simplicity Views can give a user a "personalized" view of the database structure, presenting the database as a set of virtual tables that make sense for that user. Structural simplicity Views can give a user a "personalized" view of the database structure, presenting the database as a set of virtual tables that make sense for that user.

Consistency A view can present a consistent, unchanged image of the structure of the database, even if the source tables are split, restructured, or renamed. Consistency A view can present a consistent, unchanged image of the structure of the database, even if the source tables are split, restructured, or renamed. Data Integrity If data is accessed and entered through a view, the DBMS can automatically check the data to ensure that it meets the specified integrity constraints. Data Integrity If data is accessed and entered through a view, the DBMS can automatically check the data to ensure that it meets the specified integrity constraints.

Following is an example to update the age of Ramesh: Following is an example to update the age of Ramesh: 1. SQL > UPDATE CUSTOMERS_VIEW SET AGE = 35 SET AGE = 35 WHERE name='Ramesh'; WHERE name='Ramesh'; 2. SQL > DELETE FROM CUSTOMERS_VIEW WHERE age = 22; WHERE age = 22; 3. You need a way to drop the view if it is no longer needed. DROP VIEW CUSTOMERS_VIEW;

What is Materialized View in database Materialized views are also logical view of our data driven by select query but the result of the query will get stored in the table or disk, When we see the performance of Materialized view it is better than normal View because the data of materialized view will stored in table and table may be indexed so faster Materialized views are also logical view of our data driven by select query but the result of the query will get stored in the table or disk, When we see the performance of Materialized view it is better than normal View because the data of materialized view will stored in table and table may be indexed so fasterindexed

Whenever a query or an update addresses an ordinary view's virtual table, the DBMS converts these into queries or updates against the base tables. Whenever a query or an update addresses an ordinary view's virtual table, the DBMS converts these into queries or updates against the base tables. A materialized view takes a different approach in which the query result is cached as a concrete table that may be updated from the original base tables from time to time. This enables much more efficient access, at the cost of some data being potentially out-of-date A materialized view takes a different approach in which the query result is cached as a concrete table that may be updated from the original base tables from time to time. This enables much more efficient access, at the cost of some data being potentially out-of-datecached

In Views query result is not stored in the disk or database Materialized view allow to store query result in disk or table. when we create view using any table, rowid of view is same as original table in case of Materialized view rowid is different. Performance of View is less More In case of View we always get latest dataMaterialized view we need to refresh the view for getting latest data. No need any methodsIn case of Materialized view we need some automatic method so that we can keep MV refreshed, In case of view its only the logical view of table no separate copy of table in case of Materialized view we get physically separate copy of table

You can use materialized views to increase the speed of queries on very large databases. You can use materialized views to increase the speed of queries on very large databases. Queries to large databases often involve joins between tables, aggregations such as SUM, or both. These operations are expensive in terms of time and processing power. Queries to large databases often involve joins between tables, aggregations such as SUM, or both. These operations are expensive in terms of time and processing power. Need of Materialized View

Materialized views improve query performance by PRE- CALCULATING join and aggregation operations on the database prior to execution and storing the results in the database. The query optimizer automatically recognizes when an existing materialized view can and should be used to satisfy a request. It then transparently rewrites the request to use the materialized view. Queries go directly to the materialized view and not to the underlying detail tables. Materialized views improve query performance by PRE- CALCULATING join and aggregation operations on the database prior to execution and storing the results in the database. The query optimizer automatically recognizes when an existing materialized view can and should be used to satisfy a request. It then transparently rewrites the request to use the materialized view. Queries go directly to the materialized view and not to the underlying detail tables.

Types of Materialized Views 1) Read-Only : This type of MVs cannot send data back to the server Master tables. These server only one way communication i.e. from server to the client. 1) Read-Only : This type of MVs cannot send data back to the server Master tables. These server only one way communication i.e. from server to the client. 2) Updatable : This type of MVs can send the data, changed locally, back to the server. 2) Updatable : This type of MVs can send the data, changed locally, back to the server.

Refreshing Materialized Views To keep a materialized view up to date, it needs to be refreshed. To keep a materialized view up to date, it needs to be refreshed. There are three different ways to refresh a materialized view: There are three different ways to refresh a materialized view: Complete Complete Fast Fast Force Force

Refresh Methods 1. Complete Refresh 1. Complete Refresh essentially re-creates the materialized view essentially re-creates the materialized view 2. Fast Refresh (incrementally applies data changes ) 2. Fast Refresh (incrementally applies data changes ) To perform a fast refresh, first identifies the changes that occurred in the master since the most recent refresh of the materialized view and then applies these changes to the materialized view. To perform a fast refresh, first identifies the changes that occurred in the master since the most recent refresh of the materialized view and then applies these changes to the materialized view. 3. FORCE – does a FAST refresh in favor of a COMPLETE The default refresh option The default refresh option

Materialized View Log for Fast Refresh A materialized view log is required on a master if you want to perform a fast refresh on materialized views based on the master. The log is used to record changes to the master. A materialized view log is required on a master if you want to perform a fast refresh on materialized views based on the master. The log is used to record changes to the master. The log is designed to record changes to the master since the last refresh, and net changes since the last refresh can be identified. The log is designed to record changes to the master since the last refresh, and net changes since the last refresh can be identified.

Requirements for Fast Refresh 1. The base table must have a primary key constraint. 1. The base table must have a primary key constraint. 2. Must create an update log. 2. Must create an update log.

1) create materialized view LOCAL 1) create materialized view LOCAL 2) refresh force start with SysDate next SysDate + 7 as 2) refresh force start with SysDate next SysDate + 7 as 3) select * from local; 3) select * from local;

create materialized view LOCAL create materialized view LOCAL refresh force start with SysDate next SysDate + 7 for refresh force start with SysDate next SysDate + 7 for update as update as select * from local; select * from local;

Oracle 11g: SQL Inline View Inline View An inline view is a temporary table created by using a subquery in the FROM clause An inline view is a temporary table created by using a subquery in the FROM clause Most common usage – “TOP-N” analysis Most common usage – “TOP-N” analysis An inline view is basically a query inside another query, which makes it a subquery. However, an inline view is a subquery with a twist. It only exists inside of the FROM clause An inline view is basically a query inside another query, which makes it a subquery. However, an inline view is a subquery with a twist. It only exists inside of the FROM clause Inline views are commonly used to simplify complex queries by removing join operations and condensing several queries into a single query. Inline views are commonly used to simplify complex queries by removing join operations and condensing several queries into a single query. 22

TOP-N-ANALYSIS Top-n-analysis is a SQL operation used to rank results. Top-n-analysis is a SQL operation used to rank results. The use of top-nanalysis is useful when you want to retrieve the top-n records, or top 4 records, of a result set returned by a query. The use of top-nanalysis is useful when you want to retrieve the top-n records, or top 4 records, of a result set returned by a query. The top-n-analysis query uses an inline subquery to return a result set. The top-n-analysis query uses an inline subquery to return a result set. You can use ROWNUM in your query to assign a row number to the result set. You can use ROWNUM in your query to assign a row number to the result set. The main query then uses ROWNUM to order the data and return the top four. The main query then uses ROWNUM to order the data and return the top four.

TOP-N-ANALYSIS SELECT year, title FROM d_cds ORDER BY year ; SELECT ROWNUM as RANK, year, title FROM (SELECT year, title FROM d_cds ORDER BY year);

Oracle 11g: SQL 25 “TOP-N” Analysis (continued)