dIntroduction to Databases
Transcript of dIntroduction to Databases
-
8/9/2019 dIntroduction to Databases
1/24
Introductionto Databases
-
8/9/2019 dIntroduction to Databases
2/24
A Brief History
The land when applications ruled the world An accounting program stores accounting data A marketing program stores marketing data An operations program stores marketing data
Databases were part of the applicationprogram that nobody ever noticed (or
changed)
-
8/9/2019 dIntroduction to Databases
3/24
History ctd.
If a customer changes an address, it has tobe updated in each program
Accounting Marketing perations
-
8/9/2019 dIntroduction to Databases
4/24
Problems with the Applications Approach Data Storage
!edundancy and duplicate data Data Updating
"hanges or additions must be performed multiple times Currency of Information
#otential problem of failing to update all affected files Task-Data Dependency $iles structured, formatted and arranged to suit a specific need% &ach user maintains a separate file for their own use Individual data files are not related to other files thus integration is difficult 'sers inability to obtain additional information as needs change Difficult to share data 'sers own rather than share data
-
8/9/2019 dIntroduction to Databases
5/24
The Database Grows Up
Moores law says &very * years one of two things will happen
+oull get * the computer storage memory for the same price The price of your current memory will be cut in half
-ith more disk storage, companies were able to save more
data All of this data put the focus on the database Databases were developed as standalone systems Databases became the engine behind application programs -hy not make one database for the application programs to
feed off of. "ustomer address only gets changed once All application programs see (accounting, marketing, ops)
-
8/9/2019 dIntroduction to Databases
6/24
One Database
/tandardi0ed Data $ormat A 1data store2 for the
various applications to pullfrom
A c c o u
n t
i n g
M a
r k e t i
n g
p
e r a
t i
o n s
-
8/9/2019 dIntroduction to Databases
7/24
-
8/9/2019 dIntroduction to Databases
8/24
-
8/9/2019 dIntroduction to Databases
9/24
The %elational Database• Mathematical mapping of data
• 4o more parent to child relationships• More fleible for business
• The defacto standard in databases
• /trengthened by the rise of /=>
•
!elational Databases of note• racle
• I:M
• my/=>
• /A#
• More relational database history
• http??www%nap%edu?readingroom?books?far?ch8%html
&%$% "odd
http://www.nap.edu/readingroom/books/far/ch6.htmlhttp://www.nap.edu/readingroom/books/far/ch6.htmlhttp://www.nap.edu/readingroom/books/far/ch6.htmlhttp://www.nap.edu/readingroom/books/far/ch6.html
-
8/9/2019 dIntroduction to Databases
10/24
&lements of a %elationalDatabase
Queries(Join Tables to Get Required Fields)
Reports(make it pretty)
Table(House Data)
Table(3ouse Data)
Table(3ouse Data)
Table(3ouse Data)
… … …
Forms(User Friendly Way to nter Data)
-
8/9/2019 dIntroduction to Databases
11/24
'omponents of the Dataodel &ntities
!esources &vents
Agents !elationships
66
6M, M6 MM
-
8/9/2019 dIntroduction to Databases
12/24
&ntities
Identify resources, events and agents (found on rightside of verview Activity Diagram) "ommon resources
Inventory "ash Accounts
"ommon events #urchase, !eceipt of Inventory, #ay ;endor !eceive rder, #ick @oods, /hip rder, :ill, !eceive "ash
"ommon Agents "ustomer, ;endor, &mployee
-
8/9/2019 dIntroduction to Databases
13/24
%elationships
!elationships between entities are determined byanaly0ing the activity diagram (or narrative ifdiagram not given) If have an ideal activity diagram, all relationships
known If a relationship eists < then the tables are linked ften relationships eist between
resources and events
events and agents events and events
To link tables, need to understand the 1type2 ofrelationship between the tables 5 called cardinality
-
8/9/2019 dIntroduction to Databases
14/24
'ardinalities
The cardinality is the degree to whicheach entity participates in the relationship
>ets start by looking at some relationships
between entities so that we can see why they are set up that way
-
8/9/2019 dIntroduction to Databases
15/24
One(to(one relationship
Employee Spouse
1 1
If one instance of Employee, how many Spouses
are possibly related? Put answer by Spouse.
If one instance of Spouse, how many Employees
are possibly related? Put answer by Employee.
-
8/9/2019 dIntroduction to Databases
16/24
any(to(one relationship
Employee DepartmentM 1
If one instance of Employee, how many
Departments are possibly related? Put answer by
Department.
If one instance of Department, how manyEmployees are possibly related? Put answer by
Employee.
-
8/9/2019 dIntroduction to Databases
17/24
One(to(any relationship
Department EmployeeM1
If one instance of Employee, how many
Departments are possibly related? Put answer by
Department.
If one instance of Department, how many
Employees are possibly related? Put answer by
Employee.
-
8/9/2019 dIntroduction to Databases
18/24
any(to(any relationship
Sale ShipmentMM
If one instance of Shipment, how many Sales are
possibly related? Put answer by Sales.
If one instance of Sale, how many Shipments are
possibly related? Put answer by Shipments.
-
8/9/2019 dIntroduction to Databases
19/24
Practice#Assume most typical)"eneralcase$
Tetboo! "lass
Payment "ashier
#endor Purchase
$rder
%ecei&in'%eport
%ecei&in'"ler!
In&oiceIn&entory
Item
-
8/9/2019 dIntroduction to Databases
20/24
Di*in" Deeper
Define attributes (fields) foreach entity
"ustomer
"ustomerID
>ast4ame
Address
B%
:illingInvoiceID
InvoiceDate
"ustomerID
B%
-
8/9/2019 dIntroduction to Databases
21/24
-
8/9/2019 dIntroduction to Databases
22/24
,orei"n +ey %ules
A $oreign key is reCuired for each 66 and6M relationship
$or 6M, the foreign key is put in the 1M2 side
consisting of the primary key from the tableon the 162 side
$or 66 events, the foreign key is put in thetable representing the second event and
points back to the first event%
-
8/9/2019 dIntroduction to Databases
23/24
- relationships
-e need to create a table between all MMrelationships using the #s of the two tablesas a composite # of the table in the middle
-
8/9/2019 dIntroduction to Databases
24/24
Tables and %elationships
Inventory Table
Prod no.
Description Invoice no.
Prod no.
(ty. ordered
Invoice no.
)nit Sale Price
In&oice Date
*ame
Std. Price
Sales Clerk Table
Inventory-Sale Table Sale Table
(ty. shipped Total Sale
Customer TableAccount no.
*ame
Clerk Emp. no
+ttentionStreet
"ity
ip
State
Foreign key
Primary key
Clerk Emp. no
Account no.