DBNote01
-
Upload
usman-shabbir -
Category
Documents
-
view
213 -
download
1
description
Transcript of DBNote01
![Page 1: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/1.jpg)
Jerry PostCopyright © 2010
DATABASE
1
Database Management Systems
Chapter 1
Introduction
![Page 2: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/2.jpg)
2
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?
![Page 3: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/3.jpg)
3
Application Development with a DBMS
Database Server
Application Server
Users
Application FormsDevelopers andAdministrators
Database TablesForms, Reports,Programs
SQL Queries
Data
![Page 4: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/4.jpg)
4
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.
![Page 5: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/5.jpg)
5
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.
![Page 6: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/6.jpg)
6
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
![Page 7: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/7.jpg)
7
2. Define tables and relationships.
3. Create input forms and reports.
4. Combine as applications for users.
1. Identify business rules.
DBMS Application Design
![Page 8: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/8.jpg)
8
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
![Page 9: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/9.jpg)
9
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
![Page 10: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/10.jpg)
10
Database Tables (Access)
![Page 11: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/11.jpg)
11
Database Tables (Oracle)
![Page 12: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/12.jpg)
12
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
![Page 13: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/13.jpg)
13
DBMS Report Writer
All Data
Database EngineData Dictionary
Query Processor
Report Writer
ReportFormat
and Query
![Page 14: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/14.jpg)
14
Report Writer (Oracle 10g)
![Page 15: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/15.jpg)
Report Writer (SQL Server 2008, Visual Studio 2008)
15
![Page 16: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/16.jpg)
16
DBMS Input Forms
All Data
Database EngineData DictionaryQuery Processor
Form Builder
InputForm
Design
![Page 17: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/17.jpg)
17
DBMS Components
All Data
Database EngineData Dictionary
Security
Query Processor
FormBuilder
ReportWriter
CommunicationNetwork
3GLConnector
Program
ApplicationGenerator
![Page 18: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/18.jpg)
18
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.
![Page 19: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/19.jpg)
19
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
![Page 20: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/20.jpg)
20
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 . . .
![Page 21: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/21.jpg)
21
Web Databases
Developers
Database
Web Server
Web formsand reports
dataUsers
Reports
![Page 22: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/22.jpg)
22
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
![Page 23: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/23.jpg)
23
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
![Page 24: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/24.jpg)
24
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
![Page 25: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/25.jpg)
25
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
![Page 26: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/26.jpg)
26
Examples of Commercial Systems
Vendor Product
Oracle Oracle
Microsoft SQL ServerAccess
IBM DB2Informix
Open source PostgreSQL
MySQL (Oracle) MySQL
![Page 27: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/27.jpg)
27
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.
![Page 28: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/28.jpg)
28
Network Database
Customer
OrderItems
Ordered
Items
Entry point
Entry point
![Page 29: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/29.jpg)
29
Relational Database
Customer(CustomerID, Name, …
Order(OrderID, CustomerID, OrderDate, …
ItemsOrdered(OrderID, ItemID, Quantity, …
Items(ItemID, Description, Price, …
![Page 30: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/30.jpg)
30
Object-Oriented DBMS
CustomerCustomerIDName… Add CustomerDrop CustomerChange Address
OrderOrderIDCustomerID… NewOrderDeleteOrder…
OrderItemOrderIDItemID… OrderItemDropOrderItem…
ItemItemIDDescription… New ItemSell ItemBuy Item …
GovernmentCustomer
ContactNameContactPhoneDiscount, …
NewContact
CommercialCustomer
ContactNameContactPhone…
NewContact
![Page 31: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/31.jpg)
31
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
![Page 32: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/32.jpg)
32
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
![Page 33: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/33.jpg)
33
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.
![Page 34: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/34.jpg)
34
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
![Page 35: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/35.jpg)
35
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.
![Page 36: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/36.jpg)
36
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
}}
![Page 37: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/37.jpg)
37
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.
![Page 38: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/38.jpg)
38
SQL 99: Programming
Database
Data Types Tables, …
Persistent Stored ModulesSQLExtended SQL codeExternal language code
External Programs
Embedded SQLCall-Level Interface
CURSOR … SELECT … FETCH …
![Page 39: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/39.jpg)
39
OODBMS Vendors
GemStone Systems, Inc. Hewlett-Packard, Inc. (OpenODB) IBEX Corporation, SA. Illustra (Informix, Inc.) Matisse Software, Inc. O2 Technology, Inc. Objectivity, Inc. Object Design, Inc. ONTOS, Inc. POET Software Corporation UniSQL Unisys Corporation (OSMOS) Versant Object Technology
![Page 40: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/40.jpg)
40
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 +
![Page 41: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/41.jpg)
41
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.
![Page 42: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/42.jpg)
42
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
![Page 43: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/43.jpg)
43
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
![Page 44: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/44.jpg)
44
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
![Page 45: DBNote01](https://reader035.fdocuments.in/reader035/viewer/2022070408/563dbb6a550346aa9aacf781/html5/thumbnails/45.jpg)
45
Exercise: Report
Ant, Adam 5/5/1964Brown, Laura 225.24Chen, Charles 487.34
712.58
Bono, Sonny 8/8/1972Dieter, Jackie 664.90Jones, Joe 114.32
779.22