© 2005 by prentice hall 1 the database development process dr. emad m. alsukhni the database...
TRANSCRIPT
© 2005 by Prentice Hall© 2005 by Prentice Hall 11
The Database The Database Development ProcessDevelopment ProcessDr. Emad M. Alsukhni Dr. Emad M. Alsukhni
Modern Database Modern Database ManagementManagement
77thth Edition EditionJeffrey A. Hoffer, Mary B. Prescott, Jeffrey A. Hoffer, Mary B. Prescott,
Fred R. McFaddenFred R. McFadden
Dr. Emad M. Alsukhni22
Systems Development Life Cycle Systems Development Life Cycle (cont.)(cont.)
1- Database activity – conceptual data modeling• Analyst produces a detailed data model that identifies all the organizational data that must be managed for this information system( every data attribute is defined, all categories of data are listed, every business relationship between data entities is represented and every rule is specified)
Project Identification and Selection
Project Initiation and Planning
Analysis
Physical Design
Implementation
Maintenance
Logical Design
Analysis
2- logical database design• The conceptual data model must be transformed into a logical data model, which describes the data in terms of the data management technology that will be used to implement the database
Dr. Emad M. Alsukhni33
Enterprise Data ModelEnterprise Data Model
First step in database developmentFirst step in database development Specifies scope and general contentSpecifies scope and general content Its purpose is to create an overall picture of Its purpose is to create an overall picture of
organizational data at high level of organizational data at high level of abstraction, not the design for a particular abstraction, not the design for a particular databasedatabase
Entity-relationship diagramEntity-relationship diagram Descriptions of entity typesDescriptions of entity types Relationships between entitiesRelationships between entities Business rulesBusiness rules
Dr. Emad M. Alsukhni44
Figure 2-1 Segment from enterprise data model (Pine Valley Furniture Company) [simplified E-R diagram, repeat of figure 1.3]
Enterprise data model describes the high-level entities in an organization and the relationship between these entities
Dr. Emad M. Alsukhni55
Systems Development Life Cycle Systems Development Life Cycle (cont.)(cont.)
(figures 2-4, 2-5)(figures 2-4, 2-5)Purpose – programming, testing, training, installation, documentingDeliverable – operational programs, documentation, training materials
Database activity – database implementation• Designer writes, tests, and installs the programs that process the database• The designer will finalize all database documentation, train users, put procedures into place for the ongoing support of information system (and databse) users and load data from existing information sources (files, and databases from legacy applications plus data now needed)
Project Identification and Selection
Project Initiation and Planning
Analysis
Physical Design
Implementation
Maintenance
Logical Design
Implementation
Dr. Emad M. Alsukhni66
Systems Development Life Cycle Systems Development Life Cycle (cont.)(cont.)
(figures 2-4, 2-5)(figures 2-4, 2-5)Purpose – monitor, repair, enhanceDeliverable – periodic audits
Database activity – database maintenance• The designer adds, deletes, or changes characteristics of the structure of a database in order to meet changing business conditions• Correct errors in database design• Improve the processing speed of database applications
Project Identification and Selection
Project Initiation and Planning
Analysis
Physical Design
Implementation
Maintenance
Logical Design
Maintenance
Dr. Emad M. Alsukhni77
Dr. Emad M. Alsukhni88
Database SchemaDatabase Schema External SchemaExternal Schema
This is the view (or views) of managers and other This is the view (or views) of managers and other employees who are the database users. Can be employees who are the database users. Can be represented as a combination of the enterprise represented as a combination of the enterprise data model and a collection of detailed user viewsdata model and a collection of detailed user views
user view is a logical description of some portion user view is a logical description of some portion of an enterprise database that is required by a of an enterprise database that is required by a user to perform some taskuser to perform some task
Example, online order form used by customers of Example, online order form used by customers of PVFCPVFC
Dr. Emad M. Alsukhni99
Database SchemaDatabase Schema Conceptual SchemaConceptual Schema
Combines the different external views into a single, Combines the different external views into a single, coherent definition of the enterprise’s data coherent definition of the enterprise’s data
detailed specification of the overall structure of detailed specification of the overall structure of organizational data that is independent of any organizational data that is independent of any database management technologydatabase management technology
Internal SchemaInternal Schema: : consists of two separate schemas Logical schemaLogical schema: is the representation of data for a : is the representation of data for a
type of data management technology (e.g., relational)type of data management technology (e.g., relational) Physical schema: Physical schema: describes how data are to be describes how data are to be
represented and stored in secondary storage using a represented and stored in secondary storage using a particular DBMS (e.g., Oracle)particular DBMS (e.g., Oracle)
Dr. Emad M. Alsukhni1010
Different people have different views of the database…these are the external schema
The internal schema is the underlying design and implementation
Dr. Emad M. Alsukhni1111
Strategies for DevelopmentStrategies for Development First, you will develop a first-cut conceptual schema based on First, you will develop a first-cut conceptual schema based on
the organization’s enterprise data model and a general the organization’s enterprise data model and a general understanding of the organization's data requirements on a understanding of the organization's data requirements on a projectproject
Then you will develop user views to represent data needs for Then you will develop user views to represent data needs for the various users of this databasethe various users of this database
In most cases, an analysis of the user views will yield new In most cases, an analysis of the user views will yield new attributes and possibly entities and relationships not shown on attributes and possibly entities and relationships not shown on the conceptual schemathe conceptual schema
So, the conceptual schema is augmented with these So, the conceptual schema is augmented with these requirements , thus making the conceptual and external requirements , thus making the conceptual and external schemas consistentschemas consistent
This process of evolving the two schemas continues until the This process of evolving the two schemas continues until the schemas are fully definedschemas are fully defined
Then the internal schema (logical and physical models) are Then the internal schema (logical and physical models) are developeddeveloped
Dr. Emad M. Alsukhni1212
CASECASE
Computer-Aided Software Computer-Aided Software Engineering (CASE) – software tools Engineering (CASE) – software tools providing automated support for providing automated support for systems developmentsystems development
Dr. Emad M. Alsukhni1313
Relationship degrees specify number of entity types involved
Entity symbols
A special entity that is also a relationship
Relationship symbols
Relationship cardinalities specify how many of each entity type is allowed
Attribute symbols
Dr. Emad M. Alsukhni1414
Sample E-R Diagram (Figure 3-1)
Dr. Emad M. Alsukhni1515
What Should an Entity Be?What Should an Entity Be? SHOULD BE:SHOULD BE:
An object that will have many An object that will have many instances in the databaseinstances in the database
An object that will be composed of An object that will be composed of multiple attributesmultiple attributes
An object that we are trying to modelAn object that we are trying to model SHOULD NOT BE:SHOULD NOT BE:
A user of the database system A user of the database system An output of the database system (e.g. An output of the database system (e.g.
a report)a report)
Dr. Emad M. Alsukhni1616
Inappropriate entities
System userSystem user System outputSystem output
Appropriate entities
Figure 3-4
Dr. Emad M. Alsukhni1717
AttributesAttributes
Attribute - property or characteristic Attribute - property or characteristic of an entity typeof an entity type
Classifications of attributes:Classifications of attributes: Required versus Optional AttributesRequired versus Optional Attributes Simple versus Composite AttributeSimple versus Composite Attribute Single-Valued versus Multivalued Single-Valued versus Multivalued
AttributeAttribute Stored versus Derived AttributesStored versus Derived Attributes Identifier AttributesIdentifier Attributes
Dr. Emad M. Alsukhni1818
Identifiers (Keys)Identifiers (Keys)
Identifier (Key) - An attribute (or Identifier (Key) - An attribute (or combination of attributes) that combination of attributes) that uniquely identifies individual uniquely identifies individual instances of an entity typeinstances of an entity type
Simple Key versus Composite KeySimple Key versus Composite Key Candidate Key – an attribute that Candidate Key – an attribute that
could be a key…satisfies the could be a key…satisfies the requirements for being a keyrequirements for being a key
Dr. Emad M. Alsukhni1919
Characteristics of IdentifiersCharacteristics of Identifiers
Will not change in valueWill not change in value Will not be nullWill not be null No intelligent identifiers (e.g. No intelligent identifiers (e.g.
containing locations or people that containing locations or people that might change)might change)
Substitute new, simple keys for long, Substitute new, simple keys for long, composite keyscomposite keys
Dr. Emad M. Alsukhni2020
Figure 3-7 – A composite attribute
An attribute broken into component parts
Dr. Emad M. Alsukhni2121
Figure 3-9a – Simple key attribute
The key is underlined
Dr. Emad M. Alsukhni2222
Figure 3-9b – Composite key attribute
The key is composed of two subparts
Dr. Emad M. Alsukhni2323
Figure 3-8 – Entity with a multivalued attribute (Skill) and derived attribute (Years_Employed)
Derived from date employed and current date
What’s wrong with this?
Multivalued: an employee can have more than one skill
Dr. Emad M. Alsukhni2424
Figure 3-19 – An attribute that is both multivalued and composite
This is an example of time-stamping
Dr. Emad M. Alsukhni2525
More on RelationshipsMore on Relationships Relationship Types vs. Relationship InstancesRelationship Types vs. Relationship Instances
The relationship type is modeled as the diamond The relationship type is modeled as the diamond and lines between entity types…the instance is and lines between entity types…the instance is between specific entity instancesbetween specific entity instances
Relationships can have attributesRelationships can have attributes These describe features pertaining to the association between These describe features pertaining to the association between
the entities in the relationshipthe entities in the relationship Two entities can have more than one type of Two entities can have more than one type of
relationship between them (multiple relationship between them (multiple relationships)relationships)
Associative Entity – combination of Associative Entity – combination of relationship and entityrelationship and entity
Dr. Emad M. Alsukhni2626
Cardinality of RelationshipsCardinality of Relationships
One-to-OneOne-to-One Each entity in the relationship will have exactly Each entity in the relationship will have exactly
one related entityone related entity One-to-ManyOne-to-Many
An entity on one side of the relationship can An entity on one side of the relationship can have many related entities, but an entity on have many related entities, but an entity on the other side will have a maximum of one the other side will have a maximum of one related entityrelated entity
Many-to-ManyMany-to-Many Entities on both sides of the relationship can Entities on both sides of the relationship can
have many related entities on the other sidehave many related entities on the other side
Dr. Emad M. Alsukhni2727
Dr. Emad M. Alsukhni2828
Dr. Emad M. Alsukhni2929
Entities can be related to one another in more than one way
Dr. Emad M. Alsukhni3030
RelationRelation Definition: A relation is a named, two-dimensional table Definition: A relation is a named, two-dimensional table
of data of data Table consists of rows (records), and columns (attribute Table consists of rows (records), and columns (attribute
or field)or field) Requirements for a table to qualify as a relation:Requirements for a table to qualify as a relation:
It must have a unique name.It must have a unique name. Every attribute value must be atomic (not multivalued, not Every attribute value must be atomic (not multivalued, not
composite)composite) Every row must be unique (can’t have two rows with exactly the Every row must be unique (can’t have two rows with exactly the
same values for all their fields)same values for all their fields) Attributes (columns) in tables must have unique namesAttributes (columns) in tables must have unique names The order of the columns must be irrelevantThe order of the columns must be irrelevant The order of the rows must be irrelevantThe order of the rows must be irrelevant
NOTE: all NOTE: all relationsrelations are in are in 11stst Normal form Normal form
Dr. Emad M. Alsukhni3131
Correspondence with E-R Correspondence with E-R ModelModel
Relations (tables) correspond with entity types Relations (tables) correspond with entity types and with many-to-many relationship typesand with many-to-many relationship types
Rows correspond with entity instances and Rows correspond with entity instances and with many-to-many relationship instanceswith many-to-many relationship instances
Columns correspond with attributesColumns correspond with attributes
NOTE: The word NOTE: The word relationrelation (in relational (in relational database) is NOT the same as the word database) is NOT the same as the word relationshiprelationship (in E-R model) (in E-R model)
Dr. Emad M. Alsukhni3232
Key FieldsKey Fields
Keys are special fields that serve two main Keys are special fields that serve two main purposes:purposes: Primary keysPrimary keys are are uniqueunique identifiers of the relation in identifiers of the relation in
question. Examples include employee numbers, social question. Examples include employee numbers, social security numbers, etc. security numbers, etc. This is how we can guarantee This is how we can guarantee that all rows are uniquethat all rows are unique
Foreign keysForeign keys are identifiers that enable a are identifiers that enable a dependentdependent relation (on the many side of a relationship) to refer to relation (on the many side of a relationship) to refer to its its parentparent relation (on the one side of the relationship) relation (on the one side of the relationship)
Keys can be Keys can be simplesimple (a single field) or (a single field) or compositecomposite (more than one field)(more than one field)
Keys usually are used as indexes to speed up the Keys usually are used as indexes to speed up the response to user queries (More on this in Ch. 6)response to user queries (More on this in Ch. 6)
Dr. Emad M. Alsukhni3333
Figure 5-5: Referential integrity constraints (Pine Valley Furniture)
Referential integrity
constraints are drawn via arrows from dependent to
parent table
Dr. Emad M. Alsukhni3434
Referential integrity
constraints are implemented with
foreign key to primary key references
Dr. Emad M. Alsukhni3535
Data NormalizationData Normalization Primarily a tool to validate and Primarily a tool to validate and
improve a logical design so that it improve a logical design so that it satisfies certain constraints that satisfies certain constraints that avoid unnecessary avoid unnecessary duplication of dataduplication of data
The process of decomposing The process of decomposing relations with anomalies to produce relations with anomalies to produce smaller, smaller, well-structuredwell-structured relationsrelations
Dr. Emad M. Alsukhni3636
Well-Structured RelationsWell-Structured Relations A relation that contains minimal data redundancy A relation that contains minimal data redundancy
and allows users to insert, delete, and update and allows users to insert, delete, and update rows without causing data inconsistenciesrows without causing data inconsistencies
Goal is to avoid anomaliesGoal is to avoid anomalies Insertion AnomalyInsertion Anomaly – adding new rows forces user to – adding new rows forces user to
create duplicate datacreate duplicate data Deletion AnomalyDeletion Anomaly – deleting rows may cause a loss of – deleting rows may cause a loss of
data that would be needed for other future rowsdata that would be needed for other future rows Modification AnomalyModification Anomaly – changing data in a row forces – changing data in a row forces
changes to other rows because of duplicationchanges to other rows because of duplication
General rule of thumb: a table should not pertain to more than one entity type
Dr. Emad M. Alsukhni3737
Example – Figure 5.2bExample – Figure 5.2b
Question – Is this a relation? Answer – Yes: unique rows and no multivalued attributes
Question – What’s the primary key? Answer – Composite: Emp_ID, Course_Title
Dr. Emad M. Alsukhni3838
Anomalies in this TableAnomalies in this Table InsertionInsertion – can’t enter a new employee without – can’t enter a new employee without
having the employee take a classhaving the employee take a class DeletionDeletion – if we remove employee 140, we lose – if we remove employee 140, we lose
information about the existence of a Tax Acc information about the existence of a Tax Acc classclass
ModificationModification – giving a salary increase to – giving a salary increase to employee 100 forces us to update multiple employee 100 forces us to update multiple recordsrecordsWhy do these anomalies exist?
Because there are two themes (entity types) into one relation. This results in duplication, and an unnecessary dependency between the entities
Dr. Emad M. Alsukhni3939
Figure 5.22 -Steps in normalization
Dr. Emad M. Alsukhni4040
First Normal FormFirst Normal Form No multivalued attributesNo multivalued attributes Every attribute value is atomicEvery attribute value is atomic Fig. 5-25 Fig. 5-25 is notis not in 1 in 1stst Normal Form Normal Form
(multivalued attributes) (multivalued attributes) it is not a it is not a relationrelation
Fig. 5-26 Fig. 5-26 isis in 1 in 1stst Normal form Normal form All relationsAll relations are in 1 are in 1stst Normal Form Normal Form
Dr. Emad M. Alsukhni4141
Table with multivalued attributes, not in 1st normal form
Note: this is NOT a relation
Dr. Emad M. Alsukhni4242
Table with no multivalued attributes and unique rows, in 1st normal form
Note: this is relation, but not a well-structured one
Dr. Emad M. Alsukhni4343
Anomalies in this TableAnomalies in this Table InsertionInsertion – if new product is ordered for – if new product is ordered for
order 1007 of existing customer, customer order 1007 of existing customer, customer data must be re-entered, causing duplicationdata must be re-entered, causing duplication
DeletionDeletion – if we delete the Dining Table from – if we delete the Dining Table from Order 1006, we lose information concerning Order 1006, we lose information concerning this item's finish and pricethis item's finish and price
UpdateUpdate – changing the price of product ID 4 – changing the price of product ID 4 requires update in several recordsrequires update in several records
Why do these anomalies exist? Because there are multiple themes (entity types) into one relation. This results in duplication, and an unnecessary dependency between the entities
Dr. Emad M. Alsukhni4444
Second Normal FormSecond Normal Form 1NF PLUS 1NF PLUS every non-key every non-key
attribute is fully functionally attribute is fully functionally dependent on the ENTIRE dependent on the ENTIRE primary keyprimary key Every non-key attribute must be Every non-key attribute must be
defined by the entire key, not by only defined by the entire key, not by only part of the keypart of the key
No partial functional dependenciesNo partial functional dependencies
Dr. Emad M. Alsukhni4545
Order_ID Order_Date, Customer_ID, Customer_Name, Customer_Address
Therefore, NOT in 2nd Normal Form
Customer_ID Customer_Name, Customer_Address
Product_ID Product_Description, Product_Finish, Unit_Price
Order_ID, Product_ID Order_Quantity
Dr. Emad M. Alsukhni4646
Getting it into Second Normal Getting it into Second Normal FormForm
Partial Dependencies are removed, but there are still transitive dependencies
Dr. Emad M. Alsukhni4747
Third Normal FormThird Normal Form 2NF PLUS 2NF PLUS no transitive dependenciesno transitive dependencies
(functional dependencies on non-primary-key (functional dependencies on non-primary-key attributes)attributes)
Note: this is called transitive, because the Note: this is called transitive, because the primary key is a determinant for another primary key is a determinant for another attribute, which in turn is a determinant for a attribute, which in turn is a determinant for a thirdthird
Solution: non-key determinant with transitive Solution: non-key determinant with transitive dependencies go into a new table; non-key dependencies go into a new table; non-key determinant becomes primary key in the determinant becomes primary key in the new table and stays as foreign key in the old new table and stays as foreign key in the old table table
Dr. Emad M. Alsukhni4848
Getting it into Third Normal Getting it into Third Normal FormForm
Transitive dependencies are removed