Presentation is loading. Please wait.

Presentation is loading. Please wait.

ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals.

Similar presentations


Presentation on theme: "ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals."— Presentation transcript:

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 Information & Computer Science Department

2 Outline 1. 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

3 4. Client-Server Databases and Tools

4 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

5 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

6 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

7 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

8 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

9 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

10 Criteria for Selecting SQL Servers Cost Openness Vendor support and position Third party support Scalability Extra features

11 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 Client System Server System

12 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)

13 Few Tools Application development tools  Developer Oracle  PowerBuilderSybase  Visual Studio.netMicrosoft Data integration and analysis tools  Forest & Trees Query/reporting tools

14 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

15 ... 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

16 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

17 SQL Structured Query Language  Originally was called SEQUEL The standard language for relational DBMS Developed by IBM in 1972 SQL = DDL + DML + DCL

18 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

19 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

20 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

21 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

22 Control-of-Flow Language Batches  go IF... ELSE  IF Boolean_expression sql_statement ELSE sql_statement BEGIN... END  BEGIN statement_block END WHILE Boolean_expression sql_statement

23 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.

24 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

25 SQL Server Stored Procedure Creation Syntax create procedure procname [paramertes] as sql_statment execute procname

26 A Simple First Sproc Create Proc sprocDeleteTracksandTitle @TitleID Integer As Begin Tran Delete From Tracks Where TitleID=@TitleID Delete From Title Where TitleID=@TitleID Commit Tran Sproc name @ specifies local variable. Variables declared above AS are input or output. Variables declared below AS are internal variables. SQL with transaction

27 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

28 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

29 Trigger Creation Code Create Trigger triggername On tablename For Update | Insert | Delete As SQLcode

30 A Sample Trigger Create Trigger trig_Purchase On PurchaseDetail For Delete, Insert, Update As If exists (Select * from deleted where deleted.part is not null) Begin Update InventoryPart Set OnHand = OnHand - deleted.Qty From InventoryPart,deleted Where InventoryPart.Part = deleted.Part End if exists (select * from inserted where inserted.part is not null) Begin Update InventoryPart Set OnHand = OnHand + inserted.Qty From InventoryPart, inserted Where 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.

31 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

32 … 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

33 Methods of Accessing a Database Ad-hoc access  Interactive SQL  4GL tools Programmatic access  Embedded SQL  Call Level Interface (CLI)

34 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

35 Embedded SQL Host language Host variables Singleton SELECT Cursors SQL Communication Area (SQLCA) Precompiler Static SQL Dynamic SQL  EXECUTE IMMEDIATE  PREPARE, EXECUTE

36 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

37 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

38 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’

39 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

40 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

41 ODBC Architecture Application Driver Manager Driver Data Source Data Source Data Source ODBC Interface

42 CONNECT (db, user, pswd) SEND (“select * from...”) EXECUTE ( ) DISCONNECT () Client Application DBMS GETROW ( ) (101, ‘Dhahran’,...) GETROW ( ) (101, ‘Khobar’,...) Basic Application Steps

43 ... 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


Download ppt "ICS 434 Advanced Database Systems Dr. Abdallah Al-Sukairi Second Semester 2003 - 2004 (032) King Fahd University of Petroleum & Minerals."

Similar presentations


Ads by Google