Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.

Slides:



Advertisements
Similar presentations
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 11-1 David M. Kroenke’s Chapter Eleven: Managing Databases with SQL Server.
Advertisements

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-1 COS 346 Day 20.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 1/1 Copyright © 2004 Please……. No Food Or Drink in the class.
David M. Kroenke and David J. Auer Database Processing: F undamentals, Design, and Implementation Chapter Ten: Managing Databases with SQL Server 2008.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 8.
Fundamentals, Design, and Implementation, 9/e Chapter 14 JDBC, Java Server Pages, and MySQL.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 11.
Fundamentals, Design, and Implementation, 9/e Chapter 5 Database Design.
The SQL Query Language DML1 The SQL Query Language DML Odds and Ends.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Getting Started (Excerpts) Chapter One DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 12.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Fundamentals, Design, and Implementation, 9/e Chapter 1 Introduction to Database Processing.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 11.
Concepts of Database Management Sixth Edition
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Transforming Data Models into Database Designs
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
An Investigation of Oracle and SQL Server with respect to Integrity, and SQL Language standards Presented by: Paul Tarwireyi Supervisor: John Ebden Date:
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
Database Technical Session By: Prof. Adarsh Patel.
David M. Kroenke and David J. Auer Database Processing: F undamentals, Design, and Implementation Chapter Six: Transforming Data Models into Database Designs.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
CSE 3330 Database Concepts Stored Procedures. How to create a user CREATE USER.. GRANT PRIVILEGE.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
1 IT420: Database Management and Organization SQL Views, Triggers and Stored Procedures 17 February 2006 Adina Crăiniceanu
Chapter 10 Database Application Design David M. Kroenke Database Processing © 2000 Prentice Hall.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
A Guide to SQL, Eighth Edition Chapter Eight SQL Functions and Procedures.
David M. Kroenke and David J. Auer Database Processing: F undamentals, Design, and Implementation Chapter Seven: SQL for Database Construction and Application.
Assertions and triggers1. 2 Constraints Attribute-based CHECK constraints create table … ( postcode number(4) check (postcode > 0) ); Checked at update.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Commercial RDBMSs: Office Access and Oracle Pertemuan 13 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Seven: SQL for Database Construction and Application.
IT420: Database Management and Organization Triggers and Stored Procedures 24 February 2006 Adina Crăiniceanu
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Ten A: Managing Databases with SQL Server 2012.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Six: Transforming Data Models into Database Designs.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Seven: SQL for Database Construction and Application.
Chapter 8 Advanced SQL. Relational Set Operators UNIONINTERSECTMINUS Work properly if relations are union- compatible –Names of relation attributes must.
SQL Triggers, Functions & Stored Procedures Programming Operations.
CH 10 DB Application Design n 10.1 Functions n 10.2 Case Application n 10.3 Creating, Reading, Updating, Deleting View n 10.4 Form Design n 10.5 Report.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
Copyright © 2004 Pearson Education, Inc.. Chapter 24 Enhanced Data Models for Advanced Applications.
7.5 Using Stored-Procedure and Triggers NAME MATRIC NUM GROUP Muhammad Azwan Bin Khairul Anwar CS2305A Muhammad Faiz Bin Badrol Shah CS2305B.
Chapter Six: Transforming Data Models into Database Designs 6-1.
Chapter Seven: SQL for Database Construction and Application Processing.
A Guide to SQL, Seventh Edition
Transforming Data Models
SQL for Database Construction and Application Processing
Ch7. SQL for DB construction and Application Processing 데이터베이스시스템 (ND352) 교수 홍 기 형.
Database Processing: David M. Kroenke’s Chapter Seven:
Database Processing: David M. Kroenke’s Chapter Seven:
Chapter 7 Using SQL in Applications
Chapter 7 Using SQL in Applications
Chapter 8 Advanced SQL.
Chapter 11 Managing Databases with SQL Server 2000
Presentation transcript:

Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/2 Copyright © 2004 View Ridge Gallery  View Ridge Gallery is a small art gallery that has been in business for 30 years  It sells contemporary European and North American fine art  View Ridge has one owner, three salespeople, and two workers  View Ridge owns all of the art that it sells; it holds no items on a consignment basis

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/3 Copyright © 2004 Application Requirements  View Ridge application requirements –Track customers and their artist interests –Record gallery's purchases –Record customers' art purchases –List the artists and works that have appeared in the gallery –Report how fast an artist's works have sold and at what margin –Show current inventory in a Web page

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/4 Copyright © 2004 View Ridge Data Model

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/5 Copyright © 2004 View Ridge Data Model  Problems: the keys for WORK and TRANSACTION are huge and the key for CUSTOMER is doubtful as many customers may not have an address

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/6 Copyright © 2004 Surrogate Key Database Design

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/7 Copyright © 2004 Sample Values

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/8 Copyright © 2004 Sample Values

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/9 Copyright © 2004 Sample Values

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/10 Copyright © 2004 Sample Values

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/11 Copyright © 2004 Sample Values

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/12 Copyright © 2004 CHECK CONSTRAINT  CHECK CONSTRAINT defines limits for column values  Two common uses –Specifying a range of allowed values –Specifying an enumerated list  CHECK constraints may be used –To compare the value of one column to another –To specify the format of column values –With subqueries

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/13 Copyright © 2004 SQL Views  SQL view is a virtual table that is constructed from other tables or views  It has no data of its own, but obtains data from tables or other views  SELECT statements are used to define views –A view definition may not include an ORDER BY clause  SQL views are a subset of the external views –They can be used only for external views that involve one multi-valued path through the schema

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/14 Copyright © 2004 SQL Views  Views may be used to –Hide columns or rows –Show the results of computed columns –Hide complicated SQL statements –Provide a level of indirection between application programs and tables –Assign different sets of processing permissions to tables –Assign different sets of triggers

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/15 Copyright © 2004 Example: CREATE VIEW CREATE VIEW CustomerNameView AS SELECT Name AS CustomerName FROM CUSTOMER; SELECT * FROM CustomerNameView ORDER BY CustomerName;

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/16 Copyright © 2004 Updating Views  Views may or may not be updatable  Rules for updating views are both complicated and DBMS-specific

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/17 Copyright © 2004 Updating Views  Guidelines:

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/18 Copyright © 2004 Embedding SQL In Program Code  SQL can be embedded in triggers, stored procedures, and program code  Problem: assigning SQL table columns with program variables  Solution: object-oriented programming, PL/SQL  Problem: paradigm mismatch between SQL and application programming language –SQL statements return sets of rows; an applications work on one row at a time  Solution: process the SQL results as pseudo-files

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/19 Copyright © 2004 Triggers  A trigger is a stored program that is executed by the DBMS whenever a specified event occurs on a specified table or view  Three trigger types: BEFORE, INSTEAD OF, and AFTER –Each type can be declared for Insert, Update, and Delete –Resulting in a total of nine trigger types  Oracle supports all nine trigger types  SQL Server supports six trigger types (only for INSTEAD OF and AFTER triggers)

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/20 Copyright © 2004 Firing Triggers  When a trigger is fired, the DBMS supplies –Old and new values for the update –New values for inserts –Old values for deletions  The way the values are supplied depends on the DBMS product  Trigger applications: –Checking validity (Figure 7-14) –Providing default values (Figure 7-15) –Updating views (Figure 7-16) –Enforcing referential integrity actions (Figure 7-17, 7-18)

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/21 Copyright © 2004 Stored Procedures  A stored procedure is a program that is stored within the database and is compiled when used –In Oracle, it can be written in PL/SQL or Java –In SQL Server, it can be written in TRANSACT-SQL  Stored procedures can receive input parameters and they can return results  Stored procedures can be called from –Programs written in standard languages, e.g., Java, C# –Scripting languages, e.g., JavaScript, VBScript –SQL command prompt, e.g., SQL Plus, Query Analyzer

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/22 Copyright © 2004 Stored Procedure Advantages  Greater security as store procedures are always stored on the database server  Decreased network traffic  SQL can be optimized by the DBMS compiler  Code sharing resulting in –Less work –Standardized processing –Specialization among developers

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/23 Copyright © 2004 Using SQL In Application Code  SQL can be embedded in application programs  Several SQL statements need to be executed to populate an external view  The application program causes the statements to be executed and then displays the results of the query in the form’s grid controls

Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 7/24 Copyright © 2004 Using SQL In Application Code (cont.)  The application program also processes and coordinates user actions on a form, including –Populating a drop-down list box –Making the appropriate changes to foreign keys to create record relationships  The particulars by which SQL code is inserted into applications depend on the language and data-manipulation methodology used

Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications