jerry post copyright © 2013 database 1 database management systems chapter 1 introduction
TRANSCRIPT
2
Objectives
What is a database? What do database applications look like? 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 potential problems exist with a DBMS approach? What is an application? What databases are used with this book? What are the first steps to start a project?
Sample Applications
Web site downloads Sally’s Pet Store Rolling Thunder Bicycles CornerMed All Powder Board and Ski Shop (Workbooks)
Database systems Microsoft Access includes tables, data, forms, reports Microsoft SQL Server includes tables, data Oracle includes tables, data
3
Sally’s Pet Store Employee Form
4
Users see a form with controls to help them enter and edit data.
The data items are stored in the database but the form could be located on a single computer, a Web site, or even a mobile application.
Sample Purchase Order
5
The order form is more complex and handles data entry for the order itself as well as the individual items being purchased in the detail/repeating section.
6
Application Development with a DBMS
Database Server
Application Server
Users
Application FormsDevelopers andAdministrators
Database TablesForms, Reports,Programs
SQL Queries
Data
7
Goal: Build a Business Application
Tools:Database DesignSQL (queries)Programming
Des
ign
SQ
L
Pro
gram
Des
ign
SQ
L
Pro
gram
Best:Spend your timeon design and SQL.
Worst:Compensate for poor designand limited SQL with programming.
8
DBMS: Database Management System
Database A collection of data stored in a standardized format, designed to be shared by
multiple users. Database Management System
Software that defines a database, stores the data, supports a query language, produces reports, and creates data entry screens.
9
Application Development
Feasibility Identify scope, costs, and schedule
Implementation Transfer data, install, train, review
Development Create forms, reports, and help; test
Design Define tables, relationships, forms, reports
Analysis Gather information from users
tasks
time
10
2. Define tables and relationships.
3. Create input forms and reports.
4. Combine as applications for users.
1. Identify business rules.
DBMS Application Design
11
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
12
DBMS Engine, Security, Utilities
DataTables
DatabaseEngine
ProductItemID Description887 Dog food946 Cat food
OrderOrderID ODate9874 3-3-979888 3-9-97
CustomerCustomerID Name1195 Jones2355 Rojas
ProductItemID Integer, UniqueDescription Text, 100 char
CustomerCustomerID Integer, UniqueName Text, 50 char
SecurityUser IdentificationAccess Rights
Utilities
Concurrency andLock Manager
Backup andRecovery
Administration
DataDictionary
15
DBMS Query Processor
Field Category AnimalID
Table Animal Animal
Totals Group By Count
Sort Descending
Criteria
Or
AnimalIDNameCategoryBreed
Animal
All Data
Database EngineData Dictionary
Query Processor
Category CountOfAnimalID
Dog 100
Cat 47
Bird 15
Fish 14
Reptile 6
Mammal 6
Spider 3
16
DBMS Report Writer
All Data
Database EngineData Dictionary
Query Processor
Report Writer
ReportFormat
and Query
19
DBMS Input Forms
All Data
Database EngineData DictionaryQuery Processor
Form Builder
InputForm
Design
20
DBMS Components
All Data
Database EngineData Dictionary
Security
Query Processor
FormBuilder
ReportWriter
CommunicationNetwork
3GLConnector
Program
ApplicationGenerator
21
Advantages of Database Approach
Minimal data redundancy. Data consistency. Integration of data. Sharing of data. Enforcement of standards. Ease of application development. Uniform security, privacy and integrity. Data independence.
22
Database Management Approach
Data is most importantData defined firstStandard format
Access through DBMSQueries, Reports, FormsApplication Programs3GL Interface
Data independenceChange data definition without
changing codeAlter code without changing dataMove/split data without changing
code
All Data
DBMS
Program1 Program2QueriesReports
23
Modifying Data with DBMS
Add cell number to employee tableOpen table definitionAdd data element If desired, modify reports
Use report writerNo programming
Existing reports, queries, code will all run as before with no changes.
Field Name Data Type Description
EmployeeID Number Autonumber..TaxpayerID Text Federal IDLastName TextFirstName Text . . . Phone Text . . .
CellPhone Text Cellular . . .
25
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
26
File Method Problems
Files defined in programCannot read file without definitionHard to find definitionEvery time you alter file, you must rewrite codeChange in a program/file will crash other codeCannot tell which programs use each file
Multiuser problemsConcurrencySecurity
AccessBackup & Restore
Efficiency IndexesProgrammer talent
System Application
27
Old File Method/3GL
Data Definition File 1 … File 2 …
Data Definition File A File 2 File C …
Pay History
Benefits
Employee
EmployeeChoices
FilesProgramsPayroll
Benefits
28
Example of File Method v DBMS
File Division01 Employees 02 ID 02 Name 02 Address
01 Department 02 ID 02 . . .
COBOL
112 Davy Jones 999 ElmStreet . . . 113 Peter Smith101 Oak St . . .
Employee File
More programsFile Division01 Employees...
Add to file (e.g.Cell phone)Write code to copy employee file
and add empty cell phone slot.Find all programs that use
employee file.Modify file definitions.Modify reports (as needed)Recompile, fix new bugs.
Easier: Keep two employee files?
02 Cell Phone
29
Examples of Commercial Systems
Vendor Product
Oracle OracleMySQL
Microsoft SQL ServerAccess
IBM DB2Informix
Open source PostgreSQL
30
Hierarchical Database
Customers
Orders
Item Description Quantity998 Dog Food 12764 Cat Food 11
Items
Customer
Order
Items Ordered
To retrieve data, you must start at the top (customer). When you retrieve a customer, you retrieve all nested data.
32
Relational Database
Customer(CustomerID, Name, …
Order(OrderID, CustomerID, OrderDate, …
ItemsOrdered(OrderID, ItemID, Quantity, …
Items(ItemID, Description, Price, …
33
Object-Oriented DBMS
CustomerCustomerIDName… Add CustomerDrop CustomerChange Address
OrderOrderIDCustomerID… NewOrderDeleteOrder…
OrderItemOrderIDItemID… OrderItemDropOrderItem…
ItemItemIDDescription… New ItemSell ItemBuy Item …
GovernmentCustomer
ContactNameContactPhoneDiscount, …
NewContact
CommercialCustomer
ContactNameContactPhone…
NewContact
34
Base Data Types
Numbers Integers Reals
Text Length International
Date/Time Images
Bitmap Vector
Sound Samples MIDI
Video
Numbers,Text, andDates
Images
Sound
Video
Input Process Output
12 + 8 = 20000001100000001000----------------000010100 20
001000000000000000001000000000000010010110000011000011011011111111111100111111111111111110111111111111111100011111
8 9 20 7 8 19 5 6 15000001000 000001001 000010100 .....
pitch,volume
time
0010101011111010101010010101010101111010001100101011011
0010101011111010101010010101010101111010001100101011011
0010101011111010101010010101010101111010001100101011011
0010101011111010101010010101010101111010001100101011011
0010101011111010101010010101010101111010001100101011011
35
Objects
Object Definition--encapsulation.Object NamePropertiesMethods
Often need to ignore inheritance.Combine into one table.Use multiple tables and link
by primary key.More efficient.Need to add rows to many
tables.
Customer
CustomerIDAddressPhone
AddCustomerDropCustomer
Class name
Properties
Methods
Commercial
ContactVolumeDiscount
ComputeDiscount
Government
ContactBalanceDue
BillLateFeesAddCustomer
Inheritance
Polymorphism
36
Objects in a Relational Database
CustomerIDAddressPhone
Customer
CustomerIDContactVolumeDiscount
CommercialCustomer
CustomerIDContactBalanceDue
GovernmentCustomer
Separate inherited classes. Link by primary key. Adding a new customer
requires new rows in each table.
Definitely need cascade delete.
37
OO Difficulties: Methods
Database Object
CustomerMethod:
Add New CustomerApplication
CustomerNameAddressPhone
Personal Computer
Unix Server
IBM Server
Program code
Database Object
How can a method run on different computers?
Different processors use different code.
Possibility: Java
38
SQL 99: OO Features
Abstract data type User defined data types. Equality and ordering functions. Encapsulation: Public, Private, Protected. Inheritance.
Sub-tables that inherit all columns from another table.
Persistent Stored Modules (Programming Language). Create methods. SQL and extensions. External language.
User defined operators. Triggers for events. External language support
Call-Level Interface (CLI)Direct access to DBMS
Embedded SQLSQL commands in an external language.
39
Abstract Data Types
GeoPointLatitudeLongitudeAltitude
GeoLineNumberOfPointsListOfGeoPoints
RegionID Name Size Superset MapLine …12 Europe … World394 Spain … Europe222 France … Europe
Procedure: DrawRegion{
Find region components.SQL: Select …
For each component {Fetch MapLineSet line attributesMapLine.Draw
}}
40
SQL 99 Sub-Tables
CREATE SET TABLE CommercialCustomer(
Contact VARCHAR,VolumeDiscount NUMERIC(5,2)
)UNDER Customer;
CREATE SET TABLE Customer(
CustomerID INTEGER,Address VARCHAR,Phone CHAR(15)
)
CustomerIDAddressPhone
Customer
ContactVolumeDiscount
CommercialCustomer
Inherits columnsfrom Customer.
41
SQL 99: Programming
Database
Data Types Tables, …
Persistent Stored ModulesSQLExtended SQL codeExternal language code
External Programs
Embedded SQLCall-Level Interface
CURSOR … SELECT … FETCH …
Key-Value Pairs: Cassandra
Example: Web-based, Social networks Hundreds of millions of users Complex and large data: photos, files, blogs/large text
Focus on keys and complex data, and timestamp/versions UserID + e-mail, name, Web URL Photo Name+ timestamp, image file Definitely not relational, and does not attempt to enforce relationships Terminology is confusing compared to relational; so details not in this chapter
Focus on ability to split data across thousands of servers Massively parallel All machines can operate independently
43
44
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 - $2000 Large: $100,000 +
45
How do you sell a DBMS approach?
Applications change a lot, but same data. Need for ad hoc questions and queries. Need to reduce development times. Need shared data. Improve quality of data. Enable users to do more development.
46
Building the Right System: Feasibility
Costs 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
Benefits 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
Easy to estimate Hard to value
47
Economic Feasibility: NPV
Year Benefits Costs Net0 0 50000 -500001 18000 5000 130002 18000 5000 130003 18000 5000 130004 18000 5000 130005 18000 5000 13000
Discount Rate0.05 0.07 0.10
NPV $6,283.20 $3,302.57 ($719.77)
=NPV(B14,$D$7:$D$11)+$D$6
=NPV(rate, range) + starting
48
Exercise: Build a First Database
Employee(EmployeeID, LastName, FirstName, Address, DateHired)
332 Ant Adam 354 Elm 5/5/1964442 Bono Sonny 765 Pine 8/8/1972553 Cass Mama 886 Oak 2/2/1985673 Donovan Michael 421 Willow 3/3/1971773 Moon Keith 554 Cherry 4/4/1972847 Morrison Jim 676 Sandalwood 5/5/1968
Client(ClientID, LastName, FirstName, Balance, EmployeeID)1101 Jones Joe 113.42 4422203 Smith Mary 993.55 6732256 Brown Laura 225.44 3324456 Dieter Jackie 664.90 4425543 Wodkoski John 984.00 8476673 SanchezPaula 194.87 7737353 Chen Charles 487.34 3327775 Hagen Fritz 595.55 6738890 Hauer Marianne 627.39 7739662 Nguyen Suzie 433.88 5539983 Martin Mark 983.31 847