Download Chapter 9

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Serializability wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Microsoft Access wikipedia , lookup

Oracle Database wikipedia , lookup

IMDb wikipedia , lookup

SQL wikipedia , lookup

Relational algebra wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Ingres (database) wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database wikipedia , lookup

Versant Object Database wikipedia , lookup

ContactPoint wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Chapters IV, XV, and XVI
Database
Management
Systems
Edited by: Dr. El-Masry
1
What’s the Difference
Between a Database and a
Spreadsheet??
2
Flat-File Environment
User 1
Transactions
Data
Program 1
A,B,C
User 2
Transactions
Program 2
X,B,Y
User 3
Transactions
Program 3
L,B,M
Data Redundancy & Flat-File Problems
(Advantages of DataBase Systems)
Data Storage - creates excessive storage
costs of paper documents and/or magnetic
form
Data Updating - any changes or additions
must be performed multiple times
Currency of Information - potential problem
of failing to update all affected files
Task-Data Dependency - user’s inability to
obtain additional information as his or her
needs change
4
Database Approach (Figure 4-2)
User 1
Transactions
Database
Program 1
User 2
Transactions
Program 2
User 3
Transactions
Program 3
D
B
M
S
A,
B,
C,
X,
Y,
L,
M
Elements of the Database Approach
System Development
Process
Database
Administrator
Applications
Transactions
U
S
E
R
S
Transactions
Transactions
User
Programs
User
Programs
User
Programs
User Queries
DBMS
Data
Definition
Language
Data
Manipulation
Language
Query
Language
Host
Operating
System
Physical
Database
4 Elements of the DB
Approach
Users
Database Administrator (DBA)
DBMS—software that runs the DB
Physical database
7
Users
Access DB in two ways:
User programs
Queries (SQL)
8
DBA
Personal responsible for maintaining
the DB:
1- Responsible for maintaining the data dictionary
Ex: What is meant by “customer”
Complete description of entities and their attributes in
the DB
2- Responsible for the backup and recovery of the
database
3- Responsible for the logical security of the database
(establishing an effective password system).
9
Physical Database
The lowest level of the DB
The magnetic spots on the hard drive
10
DBMS Features
User Programs - make the presence of the DBMS
transparent to the user
Direct Query - allows authorized users to access
data without programming
Application Development - user created
applications
Backup and Recovery - copies database
Database Usage Reporting - captures statistics on
database usage (who, when, etc.)
Database Access - authorizes access to sections of
11
the database
Internal Controls and
DBMS
The purpose of the DBMS is to provide
controlled access to the database.
The DBMS is a special software system
programmed to know which data
elements each user is authorized to
access and deny unauthorized
requests of data.
12
Data Definition Language
(DDL)
DDL is a programming language used to define
the database to the DBMS (Pg. 111).
The DDL identifies the names and the relationship of all
data elements, records, and files that constitute the
database.
Viewing Levels (abstract):
internal view - physical arrangement of records (1)
conceptual view - representation of database (1)
(ERD is conceptual view) (schema)
user view - the portion of the database each user
views (many) (subschema)
Refer to the SQL DDL handout.
13
Data Manipulation
Language (DML)
DML is the proprietary programming language
that a particular DBMS uses to insert, update,
process, store, and delete data (Pg. 111).
Entire user programs may be written in the
DML, or selected DML commands can be
inserted into universal programs, such as
COBOL and FORTRAN.
Refer to the SQL DML handout.
14
Data Query Language (DQL)
The query capability permits end users
and professional programmers to access
data in the database without the need for
conventional programs (Pg. 111).
IBM’s Structured Query Language (SQL)
is a fourth-generation language that has
emerged as the standard query language.
Refer to the SQL DQL handout.
15
Steps in Designing a
Database
 Phase I: Prepare the conceptual model (ERD) (Pgs. 554-556)
Identify the entities
Identify the relationships between the entities
Prepare the ER diagram (ERD)
 Phase II: Specify the logical design (relational schema)
Form the tables and relationships (associations) between tables
Show the links between the primary keys and foreign keys.
 Phase III: Normalize the tables
Final tables in third normal form should be free of anomalies.
 Phase IV: Implement the physical design
Develop the physical structures
Populate the tables
Query the tables
Access Lab. in weeks 8 and 9.
16
Phase 1
Prepare the Conceptual
Model
Draw an ERD to
capture the
process.
17
ER-Diagram Symbols
Entity
Primary Key
Relationship
Attribute
An Entity
...is an
individual object
concept
event
...may be a specific
tangible object
intangible object
Entity Class is a collection of entities with
similar attributes.
19
Attributes
A property of an entity that we choose to record (of
interest to an organization).
CUSTOMER (entity)
PRODUCT (entity)
customer #
product #
name
description
address
finish
telephone no.
price
balance
qty. on hand
20
Cardinalities
(Maximum cardinalities
Entity
Relationship method)
Entity(Pg. 566)
Salesperson
1
1
Customer
Vendor
M
Assigned
Places
Supplies
1
M
M
Car
Order
Inventory
Example of a Relationship Linking
Two Entities
CUSTOMER
1
M
places
Order Number
Name
ORDER
Item #
Number
22
ERD Exercises
Hospital ERD Exercise (handout)
University ERD Exercise (handout)
23
Relational Model Data
Linkages (>1 table)
 No explicit pointers are present. The data are viewed as a
collection of independent tables.
 Relations are formed by an attribute that is common to
both tables in the relation.
 Assignment of foreign keys:
if 1 to many association, the primary key on the one
side is embedded as the foreign key on the many side.
if many to many association, create a new relation with
the primary keys of the two entities as its primary key
if 1 to 1 association, either of the tables’ primary keys
may be the foreign key and is embedded in the other table
Remark:
Mandatory versus optional entities distinction: If there is a
mandatory/optional relationship, then primary on the mandatory
side becomes foreign on the optional side.
24
ER-Diagram using REA Model
R
Inventory
E
M
Line items
M
A
M
Sales
1
Party to
M
Sales
person
M
1
Pays for
Made to
Customer
1
M
M
1
Cash
Increases
M
Cash
Collections M
Received
from
1
Received
by
Cashier
34
Phase 2
Specify the Logical Design
(Relational schema)
Create a list with all
the relational tables
and connect them.
26
Logical Data Structures
 A particular method used to organize records in a database is called the
database’s structure.
 The objective is to develop this structure efficiently so that system
developers can build the database in less time. Also, data can be
accessed quickly and easily using the schema.
 Types of structures include for example:
 hierarchical (AKA the tree structure)
 Relational (the one used in this class)
 Important Rule: In a relational schema, arrows linking the primary key
and the foreign key will always point from foreign key to primary key.
 Example: Pg. 597
 Relational Schema Exercises:
 Hospital schema exercise (handout)
 University schema exercise (handout)
27
The Relational Model
The relational model portrays data in the
form of two dimensional tables:
relation - the database table
attributes (data elements) - form
columns
tuples (records) - form rows
data - the intersection of rows and columns
28
Properly Designed Relational Tables
No repeating values - All occurrences at
the intersection of a row and column are a
single value.
The attribute values in any column must all
be of the same class.
Each column in a given table must be
uniquely named.
Each row in the table must be unique in at
least one attribute, which is the primary key.
29
Phase 3
Normalize the tables
Transform
unnormalized tables
into tables in 3rd
normal form .
30
Why Do We Normalize?
(Three Types of Anomalies Pgs. 114-116)
 Insertion Anomaly: A new item
cannot be added to the table until
at least one entity uses a
particular attribute item.
 Deletion Anomaly: If an
attribute item used by only one
entity is deleted, all information
about that attribute item is lost.
 Update Anomaly: A modification
on an attribute must be made in
each of the rows in which the
attribute appears.
 Anomalies can be corrected by
creating relational tables.
31
Advantages of Relational
Tables
Removes all three anomalies
Various items of interest (customers,
inventory, sales) are stored in separate
tables.
Space is used efficiently.
Very flexible. Users can form ad hoc
relationships.
32
The Normalization Process
A process which systematically splits
unnormalized complex tables into smaller
tables that meet two conditions:
all nonkey (secondary) attributes in the table are
dependent on the primary key
all nonkey attributes are independent of the other
nonkey attributes
When unnormalized tables are split and reduced
to third normal form, they must then be linked
together by foreign keys.
Refer to handout on normalization
Normalization handout exercises
33
Steps in Normalization
Table with
repeating groups
Remove
repeating
groups
First normal
form 1NF
Remove
partial
dependencies
Second normal
form 2NF
Third normal
form 3NF
Higher normal
forms
Remove
transitive
dependencies
Remove
remaining
anomalies
Auditors/Accountants and
Data Normalization
The update anomaly can generate conflicting and
obsolete database values.
The insertion anomaly can result in unrecorded
transactions and incomplete audit trails.
The deletion anomaly can cause the loss of
accounting records and the destruction of audit
trails.
 Auditors and accountants should have an
understanding of the data normalization process
and be able to determine whether a database is
properly normalized.
35
Phase 4
Implement the Physical
Design
Implement in
Access (or other
DB program)
36
Physical Database Design
 Transition from theoretical to physical aspects of
database
IS  IT
Develop the physical structures
 Decisions about software and hardware
Implementation
 Establish internal controls
 Populate the database with data
 Produce physical user views (multiple)
 Query the database
 Access Lab. in weeks 8 and 9.
37