Presentation is loading. Please wait.

Presentation is loading. Please wait.

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7/8 Structured Query.

Similar presentations


Presentation on theme: "DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7/8 Structured Query."— Presentation transcript:

1 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7/8 Structured Query Language III

2 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-2 A View A view is a structured list of data attributes from the entities or semantic objects defined in the data model A view is a virtual table whose contents are defined by a query A view can be materialized or formatted as an on-line form or a hard-copy report

3 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-3 Why Views? 1.Security User authorized access 2.Query Simplicity Multi-table queries become single-table results 3.Structural Simplicity User personalized access 4.Insulation from Change Presents consistent image of DB 5.Data Integrity Data access, entry via view can be checked via DBMS

4 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-4 Why Not? 1.Performance 2.Update Restrictions 3.Views are not backups!

5 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-5 Creating Views Must have permission If columns specified, query select must match Data type, length & constraints derived from source tables

6 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-6 Types of Views Horizontal Vertical Row/Column Subset Grouped Joined

7 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-7 Horizontal Views CREATE VIEW viewname AS query; Show Eastern region salespeople DROP VIEW eastreps; CREATE VIEW eastreps AS select * from salesreps where rep_office in ( select office from offices where region = ‘Eastern’);

8 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-8 Joined Views Show the orders and amounts, but with names of employees & customers instead of numbers. DROP VIEW order_info; CREATE VIEW order_info AS select order_num, name, company, amount from orders, salesreps, customers where rep=empl_num and cust=cust_num;

9 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-9 Update of View also updates underlying table, but view must meet certain conditions: Must have update privileges View must be 1:1 w/underlying table One table only Updating a View

10 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-10 Insert into Eastreps (empl_num, name, rep_office, hire_date) values (113, ‘Jake Kimball’, 11, ’14-apr-2003’); Insert into Order_Info (order_num, name, company, amount) values (999999, ‘New Rep’, ‘New Co’, 50000); Updating a View

11 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-11 Triggers Triggers are stored procedures that are invoked at a given time based on an action. –Time: Before, After, Instead Of –Actions: Insert, Delete, Update Advantages: Auditing, Cascade, Enforce Relationships, Procedure Invocation Disadvantages: Performance

12 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-12 Triggers create trigger after_insert_bkup after insert on orders begin insert into ordersbkup select * from orders where not exists (select * from ordersbkup where ordersbkup.order_num = orders.order_num); end ;

13 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-13 Correlated Subquery A correlated subquery looks similar to a regular subquery A regular subquery can be processed from the bottom up For a correlated subquery, the processing is nested, i.e., a row from an upper query statement is used in comparison with rows in a lower-level query Useful in checking for duplicates

14 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-14 Database Redesign Three principles for database redesign: –Measure twice and cut once: understand the current structure and contents of the database before making any structure changes –Test the new changes on a test database before making real changes –Create a complete backup of the operational database before making any structure changes Technique: Reverse Engineering (RE)

15 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-15 Reverse Engineering (RE) Reverse engineering (RE) is the process of reading and producing a data model from a database schema A reverse engineered (RE) data model: –Provides a basis to begin the database redesign project –Is neither truly a conceptual nor an internal schema as it has characteristics of both –Should be carefully reviewed because it almost always has missing information

16 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-16 Database Backup and Test Databases Before making any changes to an operational database: –A complete backup of the operational database should be made –Any proposed changes should be thoroughly tested Three different copies of the database schema used in the redesign process: –A small test database for initial testing –A large test database for secondary testing –The operational database

17 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-17 Database Redesign Changes Changing tables and columns –Changing table names –Adding and dropping table columns –Changing data type or constraints –Adding and dropping constraints Changing relationships –Changing cardinalities –Adding and deleting relationships –Adding and removing relationship for de- normalization


Download ppt "DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7/8 Structured Query."

Similar presentations


Ads by Google