You are on page 1of 45

D

A Database Management
T Systems
A
B
Chapter 1
A
Introduction
S
Jerry Post
E
Copyright © 2010
1

Objectives







What is a database?
How are databases used to build applications?
What are the major components of a database management system?
What are the advantages of using a database management system?
What are the main database management systems?
How have database management systems changed over time?
What databases are used with this book?
What are the first steps to start a project?

2

Application Development with a DBMS
SQL Queries
Data
Database Tables
Forms, Reports,
Programs

Database Server
Application Server

Users
Developers and
Administrators

Application Forms
3

Goal: Build a Business Application

Program

SQL

Design

Program

SQL

Design

Tools:
Database Design
SQL (queries)
Programming

Best:
Spend your time
on design and SQL.

Worst:
Compensate for poor design
and limited SQL with programming.
4

designed to be shared by multiple users. and creates data entry screens.  Database Management System  Software that defines a database. supports a query language. stores the data. 5 . produces reports.DBMS: Database Management System  Database  A collection of data stored in a standardized format.

reports. test Implementation Transfer data. relationships. reports Development Create forms. train.Application Development tasks Feasibility Identify scope. and help. install. and schedule Analysis Gather information from users Design Define tables. forms. review time 6 . costs.

7 . Define tables and relationships.DBMS Application Design 1. 2. Identify business rules. 4. 3. Combine as applications for users. Create input forms and reports.

DBMS Features/Components  Database engine Storage Retrieval Update  Query Processor  Data dictionary  Utilities  Security  Report writer  Forms generator (input screens)  Application generator  Communications  3GL Interface 8 .

DBMS Engine. 100 char Integer. Utilities Product ItemID Description Order 887 Dog food OrderID ODate Customer946 Cat food 9874 3-3-97 CustomerID Name 9888 3-9-97 1195 Jones 2355 Rojas Product ItemID Customer Description CustomerID Name Integer. Unique Text. Security. 50 char User Identification Security Access Rights Backup and Recovery Utilities Data Tables Database Engine Data Dictionary Concurrency and Lock Manager Administration 9 . Unique Text.

Database Tables (Access) 10 .

Database Tables (Oracle) 11 .

DBMS Query Processor All Data Database Engine Data Dictionary Query Processor Animal AnimalID Name Category Breed Category CountOfAnimalID Dog 100 Field Category AnimalID Cat 47 Table Animal Bird 15 Totals Group By Count Fish 14 Reptile 6 Mammal 6 Spider 3 Sort Criteria Or Animal Descending 12 .

DBMS Report Writer All Data Database Engine Data Dictionary Query Processor Report Writer Report Format and Query 13 .

Report Writer (Oracle 10g) 14 .

Visual Studio 2008) 15 .Report Writer (SQL Server 2008.

DBMS Input Forms All Data Database Engine Data Dictionary Query Processor Form Builder Input Form Design 16 .

DBMS Components All Data Communication Network Database Engine Data Dictionary Security 3GL Connector Query Processor Form Report Builder Writer Application Generator Program 17 .

Sharing of data. Enforcement of standards. Data consistency. Integration of data. 18 . privacy and integrity. Uniform security. Data independence.Advantages of Database Approach         Minimal data redundancy. Ease of application development.

Reports.Database Management Approach  Data is most important  Data defined first  Standard format  Access through DBMS All Data  Queries. Forms  Application Programs  3GL Interface DBMS  Data independence  Change data definition without changing code  Alter code without changing data  Move/split data without changing code Program1 Queries Program2 Reports 19 .

. Number Text Text Text Autonumber. 20 .. . code will all run as before with no changes.Modifying Data with DBMS  Add cell number to employee table  Open table definition  Add data element  If desired. Field Name Data Type Description EmployeeID TaxpayerID LastName FirstName . modify reports  Use report writer  No programming  Existing reports. queries.. . Federal ID CellPhone Text Text Cellular ... Phone .

Web Databases Database Developers Web Server Users data Web forms and reports Reports 21 .

Drawbacks of old File methods  Uncontrolled Duplication  Wastes space  Hard to update all files  Inconsistent data  Inflexibility  Hard to change data  Hard to change programs     Limited data sharing Poor enforcement of standards Poor programmer productivity Excessive program maintenance 22 .

you must rewrite code  Change in a program/file will crash other code  Cannot tell which programs use each file  Multiuser problems  Concurrency  Security  Access  Backup & Restore  Efficiency  Indexes  Programmer talent  System  Application 23 .File Method Problems  Files defined in program  Cannot read file without definition  Hard to find definition  Every time you alter file.

Old File Method/3GL Programs Payroll Data Definition File 1 … File 2 … Benefits Data Definition File A File 2 File C … Files Pay History Benefits Employee Employee Choices 24 .

 Modify file definitions.  Add to file (e.  Find all programs that use employee file..Cell phone)  Write code to copy employee file and add empty cell phone slot. More programs File Division 01 Employees . .g.. . . Employee File 112 Davy Jones 999 Elm Street . .  Modify reports (as needed)  Recompile. . 113 Peter Smith 101 Oak St .Example of File Method v DBMS COBOL File Division 01 Employees 02 ID 02 Name 02 Address 02 Cell Phone 01 Department 02 ID 02 . fix new bugs.  Easier: Keep two employee files? 25 . .

Examples of Commercial Systems Vendor Product Oracle Oracle Microsoft SQL Server Access IBM DB2 Informix Open source MySQL (Oracle) PostgreSQL MySQL 26 .

Hierarchical Database Customers Customer Order Items Ordered Orders Items Item Description 998 Dog Food 764 Cat Food Quantity 12 11 To retrieve data. you must start at the top (customer). you retrieve all nested data. 27 . When you retrieve a customer.

Network Database Entry point Customer Order Items Ordered Items Entry point 28 .

OrderDate. Name. … 29 . ItemID. … Items(ItemID. CustomerID. Price.Relational Database Customer(CustomerID. Description. … Order(OrderID. … ItemsOrdered(OrderID. Quantity.

… ContactPhone … NewContact NewContact ItemID Description … New Item Sell Item Buy Item … 30 .Object-Oriented DBMS Order OrderID CustomerID … NewOrder DeleteOrder … OrderItem OrderID ItemID … OrderItem DropOrderItem … Customer CustomerID Name … Add Customer Drop Customer Change Address Item Government Customer Commercial ContactName Customer ContactPhone ContactName Discount.

Text.Base Data Types  Numbers  Integers  Reals  Text  Length  International  Date/Time  Images  Bitmap  Vector  Sound Input Numbers... volume 8 9 20 7 8 19 5 6 15 time 000001000 000001001 000010100 .. and Dates Images Sound Process Output 20 000001100 000001000 ---------------000010100 12 + 8 = 20 0010000000000000000 0100000000000001001 0110000011000011011 0111111111111001111 1111111111111011111 1111111111100011111 pitch. Video 00101010111 00101010111 00101010111 11010101010 11010101010 11010101010 01010101010 01010101010 01010101010 11110100011 11110100011 11110100011 00101011011 00101011011 00101011011 00101010111 00101010111 11010101010 11010101010 01010101010 01010101010 11110100011 11110100011 00101011011 00101011011  Samples  MIDI  Video 31 ..

 Use multiple tables and link by primary key.  Need to add rows to many tables.  More efficient. Properties Methods Customer CustomerID Address Phone AddCustomer DropCustomer Inheritance Commercial Contact VolumeDiscount Government Contact BalanceDue ComputeDiscount BillLateFees AddCustomer Polymorphism 32 .  Combine into one table.  Object Name  Properties  Methods  Often need to ignore inheritance.Objects Class name  Object Definition-encapsulation.

Objects in a Relational Database  Separate inherited classes.  Definitely need cascade delete.  Link by primary key. Customer CustomerID Address Phone CommercialCustomer CustomerID Contact VolumeDiscount GovernmentCustomer CustomerID Contact BalanceDue 33 .  Adding a new customer requires new rows in each table.

OO Difficulties: Methods IBM Server Unix Server Database Object Personal Computer Database Object Customer Method: Add New Customer Program code Application Customer Name Address Phone How can a method run on different computers? Different processors use different code. Possibility: Java 34 .

 User defined operators.  Triggers for events.  Equality and ordering functions.  Sub-tables that inherit all columns from another table.  External language support  Call-Level Interface (CLI)  Direct access to DBMS  Embedded SQL  SQL commands in an external language.  SQL and extensions. Private.  Encapsulation: Public.SQL 99: OO Features  Abstract data type  User defined data types.  External language.  Persistent Stored Modules (Programming Language). 35 . Protected.  Create methods.  Inheritance.

Abstract Data Types GeoPoint Latitude Longitude Altitude Procedure: DrawRegion { Find region components. SQL: Select … For each component { Fetch MapLine Set line attributes MapLine.Draw } } RegionID 12 394 222 GeoLine NumberOfPoints ListOfGeoPoints Name Europe Spain France Size … … … Superset World Europe Europe MapLine … 36 .

VolumeDiscount NUMERIC(5.SQL 99 Sub-Tables CREATE SET TABLE Customer ( CustomerID INTEGER. Address VARCHAR. VolumeDiscount 37 . Phone CHAR(15) ) Customer CustomerID Address Phone Inherits columns CREATE SET TABLE CommercialCustomer from Customer.2) CommercialCustomer ) Contact UNDER Customer. ( Contact VARCHAR.

SQL 99: Programming Database Data Types Tables. … Persistent Stored Modules SQL Extended SQL code External language code External Programs Embedded SQL Call-Level Interface CURSOR … SELECT … FETCH … 38 .

Illustra (Informix. O2 Technology. Inc. Hewlett-Packard. Inc. Inc. ONTOS. Inc. Object Design. Inc. POET Software Corporation UniSQL Unisys Corporation (OSMOS) Versant Object Technology 39 . (OpenODB) IBEX Corporation.OODBMS Vendors GemStone Systems. Inc. Inc. Objectivity. Inc.) Matisse Software. SA.

Why don’t all developers use a DBMS?  Most new projects (in last 5 years) do use a DBMS  Need specialized personnel  Programmers  Designers/Analysts  Database administrators  Need to define data for organization  Cost  PC: $400 .000 + 40 .$2000  Large: $100.

Need for ad hoc questions and queries. Improve quality of data. 41 . Enable users to do more development. Need shared data. but same data. Need to reduce development times.How do you sell a DBMS approach?       Applications change a lot.

Building the Right System: Feasibility  Costs  Benefits  Up-front/one-time  Software ($ millions !)  Hardware  Communications  Data conversion  Studies and Design  Training  On-going costs  Personnel  Software upgrades  Supplies  Support  Software & Hardware maintenance Easy to estimate  Cost Savings  Software maintenance  Fewer errors  Less data maintenance  Less user training  Increased Value  Better access to data  Better decisions  Better communication  More timely reports  Faster reaction to change  New products & services  Strategic Advantages  Lock out competitors Hard to value 42 .

$D$7:$D$11)+$D$6 =NPV(rate. range) + starting 43 .57 ($719.20 $3.302.Economic Feasibility: NPV Year Benefits 0 1 2 3 4 5 NPV 0 18000 18000 18000 18000 18000 Costs Net 50000 -50000 5000 13000 5000 13000 5000 13000 5000 13000 5000 13000 Discount Rate 0.05 0.10 $6.283.77) =NPV(B14.07 0.

34 332 7775 Hagen Fritz595.39 773 9662 Nguyen Suzie 433.90 442 5543 Wodkoski John 984.55 673 8890 Hauer Marianne 627. LastName.42 442 2203 Smith Mary 993.88 553 44 9983 Martin Mark 983.87 773 7353 Chen Charles 487.Exercise: Build a First Database Employee(EmployeeID. Address.44 332 4456 Dieter Jackie 664. DateHired) 332 442 553 673 773 847 Ant Bono Cass Donovan Moon Morrison Adam Sonny Mama Michael Keith Jim 354 Elm 765 Pine 886 Oak 421 Willow 554 Cherry 676 Sandalwood 5/5/1964 8/8/1972 2/2/1985 3/3/1971 4/4/1972 5/5/1968 Client(ClientID.00 847 6673 Sanchez Paula 194. Balance. EmployeeID) 1101 Jones Joe 113.31 847 .55 673 2256 Brown Laura 225. FirstName. FirstName. LastName.

Sonny 8/8/1972 Dieter.90 Jones.32 779.34 712.22 45 . Adam 5/5/1964 Brown.24 Chen. Laura225. Joe 114. Charles 487. Jackie664.58 Bono.Exercise: Report Ant.