ics 434 advanced database systems dr. abdallah al-sukairi [email protected] second semester 2003...

43
ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi [email protected] Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals Information & Computer Science Department

Upload: rosalyn-mckenzie

Post on 22-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

ICS 434 Advanced Database Systems

Dr. Abdallah [email protected]

Second Semester 2003 - 2004 (032)

King Fahd University of Petroleum & Minerals

Information & Computer Science Department

Dr. Abdallah [email protected]

Second Semester 2003 - 2004 (032)

King Fahd University of Petroleum & Minerals

Information & Computer Science Department

Page 2: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Outline1. The Relational Data Model: Version 2

2. Advanced Data Modeling

3. Client-Server Architecture

4. Client-Server Databases & Tools

5. Databases on the Web

6. The System Catalog

7. Query Processing and Optimization

8. Transaction Processing

9. Concurrency Control

10. Recovery

11. Administration & Security

12. Distributed Databases

13. Database Replication

14. Object-Oriented Databases

15. Data Warehousing and Data Mining

16. Other Emerging Database Technologies

Page 3: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

4. Client-Server Databases and Tools

Page 4: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Client-Server Database

A multiuser relational database management system

Transaction oriented processing

Security through accounts, permissions and views

Rules and triggers to enforce integrity

Examples: Oracle, DB2, SQLServer, Sybase, MySQL

Page 5: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Oracle - Oracle corporation

Ideal for large scale grid and cluster computing

Currently pushing toward small business, single computer servers

Many Enterprise applications are available or included Finance management Human Resource Management Marketing Product lifecycle management ...

43% market share

Page 6: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

DB2 - IBM

Flexible to install on a wide variety of systems

Focuses on the integration of other DBMS

Data can be distributed

Has many application packages, similar to Oracle

24% Market Share

Page 7: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

SQLServer - Microsoft

Targets small business

Easy to install

Low cost of ownership

Excellent Support

Notoriously insecure Susceptible to virus and worm attacks New patches released monthly

17% Market Share

Page 8: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Adaptive Server Enterprise (ASE) - Sybase

Low resource requirements

Fast and reliable

Lower cost of ownership compared to Oracle or DB2

Popular on Wall Street due to its high transaction rate

2% Market Share

Page 9: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

MySQL - MySQL AB (Possible HW)

Open source DBMS

Supported by a for-profit company

Well known compared to other open source solutions.

Offers free GPL version and a licensed version that includes vendor support

Less popular and less scalable than Oracle, DB2 or ASE

Page 10: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Criteria for Selecting SQL Servers

Cost

Openness

Vendor support and position

Third party support

Scalability

Extra features

Page 11: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

How Front-end Tools Work

User creates query

Database server checks user’s security rights

Front-end formats query and sends it to the DBMS

Database server processes the query and returns the results to the front-end

Front-end receives the response and formats it for the user

User view and/or manipulate the data

ClientSystem

ClientSystem

ServerSystem

Page 12: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Front-end Tools Categories

Adds on to existing products Require more system resources

Application development tools OLTP (on-line transaction processing) Programming

Query/reporting tools Nonprogramming

Data integration and analysis tools EIS/DS (executive information/decision support)

Page 13: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Few Tools

Application development tools Developer Oracle PowerBuilder Sybase Visual Studio .net Microsoft

Data integration and analysis tools Forest & Trees

Query/reporting tools

Page 14: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Evaluating Front-end Tools

Easy coding Scripting language 4GLs Object-oriented features Call 3GL modules

Multiprogrammers features

Local prototyping opportunity Off-line development Rapid application development

Page 15: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

... Evaluating Front-end Tools

Broad back-end support

Adherence to existing standards ODBC

Accessibility of server-specific features

Cross-platform development

Openness

Integration with existing tools

Features, not price

Page 16: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Database Languages

Integrated with a programming language Access

High-Level Database Languages SQL

Declarative Set-at-a-time Interactive Embedded in a host language

User-friendly Query Languages QBE

4GL tools

Page 17: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

SQL

Structured Query Language Originally was called SEQUEL

The standard language for relational DBMS

Developed by IBM in 1972

SQL = DDL + DML + DCL

Page 18: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

SQL Standards

ANSI standardized SQL in 1986 and ISO standardized it in 1987

US government’s FIPS adopted ANSI/ISO standard

Revised standard called SQL89 or SQL1 was published in 1989

Due to conflicting interests from Vendors ANSI committee revised its previous work with SQL92 standard in 1992 called SQL2

SQL 92 was approximately 6 times the length of its predecessor

In 1999 ANSI/ISO released SQL 1999 called SQL3

SQL 1999 includes object relational database concepts, call level interfaces, and integrity management

Recently SQL 2003 was released which includes collection data types, cleaner object/relational specification, and references to new parts such as XML

Page 19: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

How Standard is SQL?

Most DBMSs meet SQL89, and many meet SQL92 So SQL written for one DBMS will generally work in

another DBMS with little or no changes

But each implementation of SQL is different ANSI standard doesn’t define everything Vendors opt to not comply with entire standard Vendors wish to include extra features/faster performance

Page 20: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

ANSI SQL vs. DBMS-Specific SQL

Using ANSI SQL

Maintain as much portability of code as possible

Maintain as much portability of your skill set as possible

Trade off performance and functionality

Using DBMS-Specific SQL Code

Gain added functionality not defined in SQL standard

Gain extra performance of functions optimized for specific DBMS

Trade off portability

Page 21: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Importance of SQL Today & Tomorrow

Relational databases are still king and SQL is the language of choice XML and OOP are new non-relational standards SQL is being enhanced to work with XML

SQL Server 2000 Oracle 9i Release 2

Database administrators and Back-end developers Database creation and maintenance

Front-end application programmers SQL embedded in programming language for data connectivity Client-server programming Web programming

Managers SQL concepts/syntax used for interacting with organizational databases

Page 22: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Control-of-Flow Language

Batches go

IF ... ELSE IF Boolean_expression

sql_statementELSE sql_statement

BEGIN ... END BEGIN

statement_blockEND

WHILE Boolean_expression sql_statement

Page 23: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

What are Stored Procedures

An SQL program stored inside the database

Can pass parameters in and out

Can have internal variables, case structures, if-then-else structures, etc.

Page 24: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Advantages of Stored Procedures

Callable Programming in Database Back-end Call from Front-end to handle multi-table inserts or

deletes or other complicated procedures Makes Front-end more simple

Added Security Sprocs can have permissions that the sproc users do not

Performance First time a sproc is run it is optimized and a query plan

compiled and saved The next time it is run, that query plan is used Saves the optimization and compile times

Page 25: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

SQL Server Stored Procedure Creation Syntax

create procedure procname [paramertes] as sql_statment

execute procname

Page 26: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

A Simple First Sproc

Create Proc sprocDeleteTracksandTitle @TitleID IntegerAs

Begin TranDelete From Tracks Where TitleID=@TitleIDDelete From Title Where TitleID=@TitleIDCommit Tran

Sproc name

@ specifies local variable.

Variables declared above AS are input or

output. Variables

declared below AS are internal

variables.

SQL with transaction

Page 27: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Triggers

Triggers are pieces of code that run when certain table events occur Insert Delete Update

Triggers are attached to a specific table and to a specific event for that table

Triggers cannot be called like stored procedures – they run automatically

They don’t have separate privileges

Triggers are used to maintain integrity

Page 28: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Triggers Work with Temporary Tables

Two special tables that exist only while the trigger is running On Insert

Insert table – exact copy of the row just inserted On Delete

Delete table – exact copy of the row just deleted On Update

Insert table – exact copy of the updated row Delete table – exact copy of the row before the changes

Makes triggers hard to write and debug Insert and Delete exist only during the trigger You can't look at them before or after the trigger has run In theory, you could insert them into a test table

Page 29: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Trigger Creation Code

Create Trigger triggernameOn tablenameFor Update | Insert | DeleteAsSQLcode

Page 30: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

A Sample Trigger

Create Trigger trig_PurchaseOn PurchaseDetailFor Delete, Insert, UpdateAs

If exists (Select * from deleted where deleted.part is not null) Begin

Update InventoryPartSet OnHand = OnHand - deleted.QtyFrom InventoryPart,deletedWhere InventoryPart.Part = deleted.Part

End

if exists (select * from inserted where inserted.part is not null) Begin

Update InventoryPartSet OnHand = OnHand + inserted.QtyFrom InventoryPart, insertedWhere InventoryPart.Part = inserted.Part

End

Runs on Delete or Update

Runs on Insert or Update

Temp table is joined to real table to find record to update.

Page 31: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Issues with Triggers

Nested Triggers As Triggers fire and they update related tables Thus they can trigger other triggers Can’t get over 32 levels deep, but that shouldn’t be a

problem

Order of Firing Not Guaranteed Multiple triggers can be written for the same event Update one thing Update something else Don’t make one dependent on the other, because can’t

control order If need a particular order, use a stored procedure

Page 32: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

… Issues with Triggers

Triggers Can Cause Debugging Hassles Can’t test without doing and update, insert, or delete Can’t see info in inserted and deleted because temporary Can use Print and Select statements to tell you status of

variables in mid-firing If you drop or change a table that a trigger uses won’t see

problem until a user inserts, updates, or deletes

Triggers Can Interfere With Referential Integrity Could write trigger to do a cascade delete of child records

when parent record deleted Trigger would have to be tied to deletion of parent record But FK constraint would not let parent be deleted in first

place

Page 33: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Methods of Accessing a Database

Ad-hoc access Interactive SQL 4GL tools

Programmatic access Embedded SQL Call Level Interface (CLI)

Page 34: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

The challenge of Accessing Heterogeneous Databases Data resides on different

DBMS Hardware platforms Operating systems Network systems

We do not have to wait for fully distributed databases, client-server architecture can address the heterogeneous database access problem

Front-end tools can access diverse databases

Essential to enterprises with heterogeneous databases

Page 35: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Embedded SQL

Host language

Host variables

Singleton SELECT

Cursors

SQL Communication Area (SQLCA)

Precompiler

Static SQL

Dynamic SQL EXECUTE IMMEDIATE PREPARE, EXECUTE

Page 36: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Call Level Interface

A program communicates with the DBMS through a set of function calls called the application program interface (API)

The CLI approach is used in client-server architecture

The code of the API is located on the client system

The SQL API becomes just another library for the programmer to learn

No need for a precompiler

Page 37: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Heterogeneous Database Access Issues

Programming interface Embedded SQL or CLI

Interprocess communication mechanism Named pipes, TCP/IP

Network protocol TCP/IP, NetBEUI, SPX/IPX

System catalog

SQL syntax and semantics

Page 38: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Heterogeneous Database Access Approaches

Embedded SQL The application should be precompiled with each back-

end server it accesses Source Code Compatibility

The source code must be recompiled for a new environment Unacceptable solution to software vendors and

corporates

CLI The ability to connect to various backends on a dynamic

basis, by loading a new library Binary Compatibility Dynamic link libraries or ‘database drivers’

Page 39: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

Open Database Connectivity (ODBC)

Architecture for database connectivity

Open

Vendor-neutral

ODBC interface defines the following ODBC API (function calls) SQL syntax based on X/Open and SQL CAE specs Standard set of error codes Standard way to connect to a DBMS Standard representation for data types

Page 40: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

ODBC Goals

Provide universal database access

Ease development burden

Broadens application support for databases

Built-in scalability for applications

With ODBC the client application is not required to know Location of the DBMS Communication method What vendor’s DBMS is being used

Page 41: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

ODBC Architecture

ApplicationApplication

Driver ManagerDriver Manager

DriverDriver DriverDriverDriverDriver

DataSourceData

SourceData

SourceData

SourceData

SourceData

Source

ODBC Interface

Page 42: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

CONNECT (db, user, pswd)

SEND (“select * from ...”)

EXECUTE ( )

DISCONNECT ()

ClientApplication DBMS

GETROW ( )

(101, ‘Dhahran’, ...)

GETROW ( )

(101, ‘Khobar’, ...)

Basic Application Steps

Page 43: ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi sukairi@kfupm.edu.sa Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals

... Basic Application Steps

Setting up a data source SQLConnect, SQLDriverConnect

Sending SQL to the data source SQLPrepare, SQLExecute, SQLExecuteDirect ODBC syntax Pass through

Retrieving results SQLFetch Cursors

SQLSetScrollOption, SQLSetPos Static, dynamic, Key-set driven