css/416 data design and retrieval workshop 3. css/416 workshop 32 database management systems...
DESCRIPTION
CSS/416 Workshop 33 Database management Systems Relational model Based on 1970 paper by E.F. Codd User sees all data in tables Tables can be combined using “set” operations (linked via columns) Metadata also stored in tables as above Logical design separate from physical implementationsTRANSCRIPT
CSS/416
Data Designand Retrieval
Workshop 3
CSS/416 Workshop 3 2
Database Management Systems
Terminology
Traditional MIS RDBMS
RelationalAlgebra
File Table RelationRecord Row TupleField Column Attribute
CSS/416 Workshop 3 3
Database management Systems Relational model
Based on 1970 paper by E.F. Codd User sees all data in tables Tables can be combined using “set”
operations (linked via columns) Metadata also stored in tables as above Logical design separate from physical
implementations
CSS/416 Workshop 3 4
Database Management Systems Functional Dependencies
A -> B; A determines B (A is Determinant)
Partial (PK = AB, B -> C)
CustID -> Customer Name
CSS/416 Workshop 3 5
Database Management Systems Keys
Derived from entity identifier One or more attributes (more =
composite key) Uniquely determine a row Functionally determine an entire
row’s attributes
CSS/416 Workshop 3 6
Database management systems
SID Activity Fee100 Skiing 200150 Swimming 50175 Squash 50200 Swimming 50
Modification Anomalies (multiple themes)
- Can’t insert fact that scuba diving cost $175- Cant update swimming fee- Delete SID 100=>lose skiing data
CSS/416 Workshop 3 7
Database Normalization Entities should have common theme Stages
First Normal form Second Third Others (BCNF, 4th, 5th, DK)
Impact on referential integrity Denormalize for performance (city, state, zip
is classic example)
CSS/416 Workshop 3 8
Database Normalization 1st normal form – eliminate multi-
valued attributes(repeating groups) 2nd normal – no partial key
functional dependencies 3rd normal – eliminate transitive
dependencies
CSS/416 Workshop 3 9
Database Normal FormsViolates first normal – why?
Plant Name
Eqpt Name
Plant Mgr
Eqpt Mfgr
Mfgr Addr
ethylene Final cooler, feed heater
Jim Smith
ABC Exchanger
1247 Locust
styrene Feed pump Bill Gunn XYZ Pumps
432 Broadway
styrene Feed pump Bill Gunn ABC Exchanger
1247 Locust
CSS/416 Workshop 3 10
Database NormalizationPlant Name
Eqpt Name Plant Mgr
Eqpt Mfgr
Mfgr Addr
ethylene Final cooler Jim Smith
ABC Exchanger
1247 Locust
ethylene Feed heater Jim Smith
ABC Exchanger
1247 Locust
styrene Feed pump Bill Gunn XYZ Pumps
432 Broadway
styrene Feed heater Bill Gunn ABC Exchanger
1247 Locust
1st Normal satisfied Still violates 2nd normal– why?
CSS/416 Workshop 3 11
Database NormalizationPlantName
Eqpt name
Eqpt Mfgr Mfgr Addr
ethylene
Final cooler
ABC Exchanger
1247 Locust
ethylene
Feed heater
ABC Exchanger
1247 Locust
styrene Feed pump
XYZ Pumps 432 Broadway
styrene Feed heater
ABC Exchanger
1247 Locust
PlantName
Plant Mgr
ethylene
Jim Smith
styrene Bill Gunn
2nd OK but 3rd?
CSS/416 Workshop 3 12
Database NormalizationPlantName
Eqpt name
Eqpt Mfgr
ethylene
Final cooler
ABC Exchanger
ethylene
Feed heater
ABC Exchanger
styrene Feed pump
XYZ Pumps
styrene Feed heater
ABC Exchanger
PlantName
Plant Mgr
Ethylene
Jim Smith
styrene Bill Gunn
Eqpt Mfgr
Mfgr Addr
ABC Exchanger
1247 Locust
XYZ Pumps
432 Broadway
Satisfies 3rd normal form
CSS/416 Workshop 3 13
Database Normalization BCNF – Every determinant is a
candidate key
Fourth – Multi-valued dependencies
Fifth – Can recombine relations
CSS/416 Workshop 3 14
Database Normalization
Domain Key (DK/NF) Provably free from anomalies But no one way to generate this form All constraints follow from domain
definitions and keys
CSS/416 Workshop 3 15
Database Normalization
Domain Key (DK/NF)
“The key, the whole key, and nothing but the key”
CSS/416 Workshop 3 16
Database Design Translating a model to the Database
Entities -> tables Establish primary & foreign keys Many-to-many relations ->Junction table Business rules -> triggers, constraints,
etc. Surrogate keys Security Typically done with a “CASE” tool
CSS/416 Workshop 3 17
Database Design
HasEmployee
Auto #
One-to-one
1Auto
Emp #
1
CSS/416 Workshop 3 18
Database Design
MakesMfgr
One-to-many
Mfgr #
1 NEquipment
CSS/416 Workshop 3 19
Database Design
HasInvoice
One-to-many (w/ ID Dependency
Inv #
1 NLine Item
PK = inv#, item#
CSS/416 Workshop 3 20
Database Design
Mfgr
Many-to-many
Mfgr_Eqpt
Equipment
M N
Mfg # Eqpt ID
CSS/416 Workshop 3 21
Database Design
Referred byMember
Recursive
Member #
1
1
CSS/416 Workshop 3 22
Database Design
Member
IS-A relationship (Subscriptions)
Print Online
Member#
CSS/416 Workshop 3 23
Database Design Learning teams to implement
sample relations for above E-R relationships: 1 to 1 1 to many Many to many 1 to many w/ ID Dependency Recursive IS-A
CSS/416 Workshop 3 24
SQL Two main language components
Data definition language (DDL)
Data manipulation language (DML)
CSS/416 Workshop 3 25
SQL Data definition language (DDL)
Create, alter, drop, etc. Frequently implemented via various
CASE tools: Visio, Embarcadero, ERWin, etc.
But – also very useful for database administration
CSS/416 Workshop 3 26
SQLCreate Statement
Create table patient(name varchar2(35) not null,age smallint,gender varchar2(1),account_number integer not null,primary key account_number)
<..additional constraints such as foreign keys, etc. ..>
CSS/416 Workshop 3 27
SQLSelect (Projection)Select plantname
from equipment
Select (Restriction)Select *
from equipment
where eqpt_name = ‘feed heater’
CSS/416 Workshop 3 28
SQLSelect (Selection + projection)
Select eqpt_namefrom equipmentwhere plantname = “styrene”
Sorting (Ordering)
Select *from manufacturersorder by eqpt_mfgr
CSS/416 Workshop 3 29
SQL There are many built in functions Some are called aggregate
functions Count Max Avg Etc.
ExampleSelect max(age) from dependents
CSS/416 Workshop 3 30
SQL
Joins (old syntax)
Select m.mfgr_addrfrom manufacturers m, equipment ewhere m.eqpt_mfgr = e.eqpt_mfgr
and e.plantname = ‘styrene’
CSS/416 Workshop 3 31
SQL
Joins (new syntax)
Select m.mfgr_addrfrom manufacturers minner join equipment eOn e.name = m.namewhere e.plantname = ‘styrene’
CSS/416 Workshop 3 32
SQL
Subqueries
Select m.mfg_addrfrom manufacturers mwhere eqpt_mfgr in(select e.eqpt_name from equipment e)
CSS/416 Workshop 3 33
SQLInsertInsert into equipmentvalues(‘propylene’, ‘feed heater’,
‘ABC Exchanger’)
UpdateUpdate manufacturersSet address = ‘18 Front Road’Where mfgr_name = ‘ABC Exchanger’
CSS/416 Workshop 3 34
SQL
Delete
Delete from equipmentWhere plant_name = ‘styrene’And eqpt_name = ‘feed cooler’
How many rows could this delete?
CSS/416 Workshop 3 35
SQL Exercise
Create the tables in the design exercise
Create a few sample SQL selects, etc.
Functions of a Database Application
Page 238 Figure 10-1 © 2000 Prentice Hall
CSS/416 Workshop 3 37
CRUD“the first function of a database
application is to CRUD views” Create Read Update Delete
Page 237
CSS/416 Workshop 3 38
Format or Materialize views“the second function of a database
application; the appearance of the content”
Page 238
CSS/416 Workshop 3 39
Other database functions Enforce constraints Provide for security and control Execute business logic
Page 238
E-R Diagram
Page 240 Figure 10-3b © 2000 Prentice Hall
Relational Design
Page 240 Figure 10-3c © 2000 Prentice Hall
Relational Design(w/ Surrogate Keys)
Page 240 Figure 10-3d © 2000 Prentice Hall
Relational Diagram
Page 241 Figure 10-3e © 2000 Prentice Hall
CSS/416 Workshop 3 44
View“A structured list of data items
(attributes) from the entities or semantic objects defined in the data model”
A view can be materialized or formatted as a form or report
Page 242
CSS/416 Workshop 3 45
Recordset“the result of an SQL statement”
Page 243
CSS/416 Workshop 3 46
CRUD actions on a viewRead
SELECT CUSTOMER.CustomerID, CUSTOMER.Name
FROM CUSTOMER, WORKWHERE CUSTOMER.CustomerID =
WORK.CustomerID
Page 243
CSS/416 Workshop 3 47
CRUD actions on a viewCreate
INSERT INTO CUSTOMER(CUSTOMER.Name, CUSTOMER.City)
VALUES (NewCust.CUSTOMER.Name, NewCust.CUSTOMER.City)
Page 244
CSS/416 Workshop 3 48
CRUD actions on a viewUpdate
INSERT INTO CUSTOMER(CUSTOMER.Name, CUSTOMER.City)
VALUES (NewCust.CUSTOMER.Name, NewCust.CUSTOMER.City)
Page 246
CRUD actions on a viewDelete
Cascading deletions depends on relationship cardinality
Page 247 Figure 10-6 © 2000 Prentice Hall
CSS/416 Workshop 3 50
Form
“a screen display used for data entry and edit”
Forms should... reflect the view structure make data associations graphically
clear encourage appropriate action
Page 248
CSS/416 Workshop 3 51
Forms in a GUI Environment Drop-down list Option buttons in groups Check boxes
Page 251
GUI controls
Page 252 Figure 10-10 © 2000 Prentice Hall
CSS/416 Workshop 3 53
Report DesignReports should... reflect the structure of the
underlying view handle implied objects
Page 253
CSS/416 Workshop 3 54
Enforcing Constraints Domain Uniqueness Relationship
Cardinality
1.1 and 1.N fragments orphans
Business Rule triggers
Page 256
CSS/416 Workshop 3 55
Security Horizontal Vertical
Page 264
CSS/416 Workshop 3 56
Control
System of menus
Transaction boundaries(Atomic unit of work)
Page 265