SlideShare a Scribd company logo
© 2007 by Prentice Hall© 2007 by Prentice Hall 11
Chapter 5:Chapter 5:
Logical Database Design andLogical Database Design and
the Relational Modelthe Relational Model
Modern Database ManagementModern Database Management
88thth
EditionEdition
Jeffrey A. Hoffer, Mary B. Prescott,Jeffrey A. Hoffer, Mary B. Prescott,
Fred R. McFaddenFred R. McFadden
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 22
ObjectivesObjectives
 Definition of termsDefinition of terms
 List five properties of relationsList five properties of relations
 State two properties of candidate keysState two properties of candidate keys
 Define first, second, and third normal formDefine first, second, and third normal form
 Describe problems from merging relationsDescribe problems from merging relations
 Transform E-R and EER diagrams to relationsTransform E-R and EER diagrams to relations
 Create tables with entity and relational integrityCreate tables with entity and relational integrity
constraintsconstraints
 Use normalization to convert anomalous tablesUse normalization to convert anomalous tables
to well-structured relationsto well-structured relations
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 33
RelationRelation
 Definition: A relation is a named, two-dimensional table ofDefinition: A relation is a named, two-dimensional table of
datadata
 Table consists of rows (records) and columns (attribute orTable consists of rows (records) and columns (attribute or
field)field)
 Requirements for a table to qualify as a relation:Requirements for a table to qualify as a relation:
 It must have a unique nameIt must have a unique name
 Every attribute value must be atomic (not multivalued, notEvery attribute value must be atomic (not multivalued, not
composite)composite)
 Every row must be unique (can’t have two rows with exactly theEvery 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: allNOTE: all relationsrelations are inare in 11stst
Normal formNormal form
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 44
Correspondence with E-RCorrespondence with E-R
ModelModel
 Relations (tables) correspond with entity typesRelations (tables) correspond with entity types
and with many-to-many relationship typesand with many-to-many relationship types
 Rows correspond with entity instances and withRows correspond with entity instances and with
many-to-many relationship instancesmany-to-many relationship instances
 Columns correspond with attributesColumns correspond with attributes

NOTE: The wordNOTE: The word relationrelation (in relational(in relational
database) is NOT the same as the worddatabase) is NOT the same as the word
relationshiprelationship (in E-R model)(in E-R model)
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 55
Key FieldsKey Fields
 Keys are special fields that serve two main purposes:Keys are special fields that serve two main purposes:
 Primary keysPrimary keys areare uniqueunique identifiers of the relation in question.identifiers of the relation in question.
Examples include employee numbers, social security numbers,Examples include employee numbers, social security numbers,
etc.etc. This is how we can guarantee that all rows are uniqueThis is how we can guarantee that all rows are unique
 Foreign keysForeign keys are identifiers that enable aare identifiers that enable a dependentdependent relationrelation
(on the many side of a relationship) to refer to its(on the many side of a relationship) to refer to its parentparent relationrelation
(on the one side of the relationship)(on the one side of the relationship)
 Keys can beKeys 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 theKeys 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)
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 66
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
Combined, these are a composite
primary key (uniquely identifies the
order line)…individually they are
foreign keys (implement M:N
relationship between order and product)
Figure 5-3 Schema for four relations (Pine Valley Furniture Company)
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 77
Integrity ConstraintsIntegrity Constraints
 Domain ConstraintsDomain Constraints
 Allowable values for an attribute. See TableAllowable values for an attribute. See Table
5-15-1
 Entity IntegrityEntity Integrity
 No primary key attribute may be null. AllNo primary key attribute may be null. All
primary key fieldsprimary key fields MUSTMUST have datahave data
 Action AssertionsAction Assertions
 Business rules. Recall from Ch. 4Business rules. Recall from Ch. 4
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 88
Domain definitions enforce domain integrity constraints
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 99
Integrity ConstraintsIntegrity Constraints
 Referential Integrity–rule states that any foreign key value (onReferential Integrity–rule states that any foreign key value (on
the relation of the many side) MUST match a primary key valuethe relation of the many side) MUST match a primary key value
in the relation of the one side. (Or the foreign key can be null)in the relation of the one side. (Or the foreign key can be null)
 For example: Delete RulesFor example: Delete Rules
 Restrict–don’t allow delete of “parent” side if related rows exist inRestrict–don’t allow delete of “parent” side if related rows exist in
“dependent” side“dependent” side
 Cascade–automatically delete “dependent” side rows that correspondCascade–automatically delete “dependent” side rows that correspond
with the “parent” side row to be deletedwith the “parent” side row to be deleted
 Set-to-Null–set the foreign key in the dependent side to null ifSet-to-Null–set the foreign key in the dependent side to null if
deleting from the parent sidedeleting from the parent side  not allowed for weak entitiesnot allowed for weak entities
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1010
Figure 5-5
Referential integrity constraints (Pine Valley Furniture)
Referential
integrity
constraints are
drawn via arrows
from dependent to
parent table
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1111
Figure 5-6 SQL table definitions
Referential
integrity
constraints are
implemented with
foreign key to
primary key
references
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1212
Transforming EER DiagramsTransforming EER Diagrams
into Relationsinto Relations
Mapping Regular Entities to RelationsMapping Regular Entities to Relations
1.1. Simple attributes: E-R attributes map directlySimple attributes: E-R attributes map directly
onto the relationonto the relation
2.2. Composite attributes: Use only their simple,Composite attributes: Use only their simple,
component attributescomponent attributes
3.3. Multivalued Attribute–Becomes a separateMultivalued Attribute–Becomes a separate
relation with a foreign key taken from therelation with a foreign key taken from the
superior entitysuperior entity
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1313
(a) CUSTOMER
entity type with
simple
attributes
Figure 5-8 Mapping a regular entity
(b) CUSTOMER relation
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1414
(a) CUSTOMER
entity type with
composite
attribute
Figure 5-9 Mapping a composite attribute
(b) CUSTOMER relation with address detail
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1515
Figure 5-10 Mapping an entity with a multivalued attribute
One–to–many relationship between original entity and new relation
(a)
Multivalued attribute becomes a separate relation with foreign key
(b)
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1616
Transforming EER DiagramsTransforming EER Diagrams
into Relations (cont.)into Relations (cont.)
Mapping Weak EntitiesMapping Weak Entities
 Becomes a separate relation with aBecomes a separate relation with a
foreign key taken from the superiorforeign key taken from the superior
entityentity
 Primary key composed of:Primary key composed of:
 Partial identifier of weak entityPartial identifier of weak entity
 Primary key of identifying relation (strongPrimary key of identifying relation (strong
entity)entity)
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1717
Figure 5-11 Example of mapping a weak entity
a) Weak entity DEPENDENT
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1818
NOTE: the domain constraint
for the foreign key should
NOT allow null value if
DEPENDENT is a weak
entity
Foreign key
Composite primary key
Figure 5-11 Example of mapping a weak entity (cont.)
b) Relations resulting from weak entity
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1919
Transforming EER DiagramsTransforming EER Diagrams
into Relations (cont.)into Relations (cont.)
Mapping Binary RelationshipsMapping Binary Relationships
 One-to-Many–Primary key on the one sideOne-to-Many–Primary key on the one side
becomes a foreign key on the many sidebecomes a foreign key on the many side
 Many-to-Many–Create aMany-to-Many–Create a new relationnew relation withwith
the primary keys of the two entities as itsthe primary keys of the two entities as its
primary keyprimary key
 One-to-One–Primary key on the mandatoryOne-to-One–Primary key on the mandatory
side becomes a foreign key on the optionalside becomes a foreign key on the optional
sideside
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2020
Figure 5-12 Example of mapping a 1:M relationship
a) Relationship between customers and orders
Note the mandatory one
b) Mapping the relationship
Again, no null value in the
foreign key…this is because
of the mandatory minimum
cardinality
Foreign key
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2121
Figure 5-13 Example of mapping an M:N relationship
a) Completes relationship (M:N)
The Completes relationship will need to become a separate relation
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2222
New
intersection
relation
Foreign key
Foreign key
Composite primary key
Figure 5-13 Example of mapping an M:N relationship (cont.)
b) Three resulting relations
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2323
Figure 5-14 Example of mapping a binary 1:1 relationship
a) In_charge relationship (1:1)
Often in 1:1 relationships, one direction is optional.
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2424
b) Resulting relations
Figure 5-14 Example of mapping a binary 1:1 relationship (cont.)
Foreign key goes in the relation on the optional side,
Matching the primary key on the mandatory side
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2525
Transforming EER DiagramsTransforming EER Diagrams
into Relations (cont.)into Relations (cont.)
Mapping Associative EntitiesMapping Associative Entities
 Identifier Not AssignedIdentifier Not Assigned
 Default primary key for the associationDefault primary key for the association
relation is composed of the primary keys ofrelation is composed of the primary keys of
the two entities (as in M:N relationship)the two entities (as in M:N relationship)
 Identifier AssignedIdentifier Assigned
 It is natural and familiar to end-usersIt is natural and familiar to end-users
 Default identifier may not be uniqueDefault identifier may not be unique
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2626
Figure 5-15 Example of mapping an associative entity
a) An associative entity
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2727
Figure 5-15 Example of mapping an associative entity (cont.)
b) Three resulting relations
Composite primary key formed from the two foreign keys
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2828
Figure 5-16 Example of mapping an associative entity with
an identifier
a) SHIPMENT associative entity
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2929
Figure 5-16 Example of mapping an associative entity with
an identifier (cont.)
b) Three resulting relations
Primary key differs from foreign keys
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3030
Transforming EER DiagramsTransforming EER Diagrams
into Relations (cont.)into Relations (cont.)
Mapping Unary RelationshipsMapping Unary Relationships
 One-to-Many–Recursive foreign key in theOne-to-Many–Recursive foreign key in the
same relationsame relation
 Many-to-Many–Two relations:Many-to-Many–Two relations:
 One for the entity typeOne for the entity type
 One for an associative relation in which theOne for an associative relation in which the
primary key has two attributes, both takenprimary key has two attributes, both taken
from the primary key of the entityfrom the primary key of the entity
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3131
Figure 5-17 Mapping a unary 1:N relationship
(a) EMPLOYEE entity with
unary relationship
(b) EMPLOYEE
relation with
recursive foreign
key
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3232
Figure 5-18 Mapping a unary M:N relationship
(a) Bill-of-materials
relationships (M:N)
(b) ITEM and
COMPONENT
relations
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3333
Transforming EER DiagramsTransforming EER Diagrams
into Relations (cont.)into Relations (cont.)
Mapping Ternary (and n-ary)Mapping Ternary (and n-ary)
RelationshipsRelationships
 One relation for each entity and oneOne relation for each entity and one
for the associative entityfor the associative entity
 Associative entity has foreign keysAssociative entity has foreign keys
to each entity in the relationshipto each entity in the relationship
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3434
Figure 5-19 Mapping a ternary relationship
a) PATIENT TREATMENT Ternary relationship with
associative entity
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3535
b) Mapping the ternary relationship PATIENT TREATMENT
Remember
that the
primary key
MUST be
unique
Figure 5-19 Mapping a ternary relationship (cont.)
This is why
treatment date
and time are
included in the
composite
primary key
But this makes a
very
cumbersome
key…
It would be
better to create a
surrogate key
like Treatment#
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3636
Transforming EER DiagramsTransforming EER Diagrams
into Relations (cont.)into Relations (cont.)
Mapping Supertype/Subtype RelationshipsMapping Supertype/Subtype Relationships
 One relation for supertype and for each subtypeOne relation for supertype and for each subtype
 Supertype attributes (including identifier andSupertype attributes (including identifier and
subtype discriminator) go into supertype relationsubtype discriminator) go into supertype relation
 Subtype attributes go into each subtype;Subtype attributes go into each subtype;
primary key of supertype relation also becomesprimary key of supertype relation also becomes
primary key of subtype relationprimary key of subtype relation
 1:1 relationship established between supertype1:1 relationship established between supertype
and each subtype, with supertype as primaryand each subtype, with supertype as primary
tabletable
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3737
Figure 5-20 Supertype/subtype relationships
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3838
Figure 5-21
Mapping Supertype/subtype relationships to relations
These are implemented as one-to-one
relationships
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3939
Data NormalizationData Normalization
 Primarily a tool to validate and improvePrimarily a tool to validate and improve
a logical design so that it satisfiesa logical design so that it satisfies
certain constraints thatcertain constraints that avoidavoid
unnecessary duplication ofunnecessary duplication of
datadata
 The process of decomposing relationsThe process of decomposing relations
with anomalies to produce smaller,with anomalies to produce smaller,
well-structuredwell-structured relationsrelations
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4040
Well-Structured RelationsWell-Structured Relations
 A relation that contains minimal data redundancy andA relation that contains minimal data redundancy and
allows users to insert, delete, and update rowsallows users to insert, delete, and update rows
without causing data inconsistencieswithout causing data inconsistencies
 Goal is to avoid anomaliesGoal is to avoid anomalies
 Insertion AnomalyInsertion Anomaly –adding new rows forces user to create–adding new rows forces user to create
duplicate dataduplicate 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
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4141
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
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4242
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 classinformation about the existence of a Tax Acc class
 ModificationModification–giving a salary increase to employee–giving a salary increase to employee
100 forces us to update multiple records100 forces us to update multiple records
Why do these anomalies exist?
Because there are two themes (entity types) in this
one relation. This results in data duplication and an
unnecessary dependency between the entities
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4343
Functional Dependencies and KeysFunctional Dependencies and Keys
 Functional Dependency: The value ofFunctional Dependency: The value of
one attribute (theone attribute (the determinantdeterminant))
determines the value of anotherdetermines the value of another
attributeattribute
 Candidate Key:Candidate Key:
 A unique identifier. One of the candidateA unique identifier. One of the candidate
keys will become the primary keykeys will become the primary key
 E.g. perhaps there is both credit card numberE.g. perhaps there is both credit card number
and SS# in a table…in this case both areand SS# in a table…in this case both are
candidate keyscandidate keys
 Each non-key field is functionallyEach non-key field is functionally
dependent on every candidate keydependent on every candidate key
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4444
Figure 5.22 Steps in normalization
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4545
First Normal FormFirst Normal Form
 No multivalued attributesNo multivalued attributes
 Every attribute value is atomicEvery attribute value is atomic
 Fig. 5-25Fig. 5-25 is notis not in 1in 1stst
Normal FormNormal Form
(multivalued attributes)(multivalued attributes)  it is not ait is not a
relationrelation
 Fig. 5-26Fig. 5-26 isis in 1in 1stst
Normal formNormal form
 All relationsAll relations are in 1are in 1stst
NormalNormal
FormForm
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4646
Table with multivalued attributes, not in 1st
normal form
Note: this is NOT a relation
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4747
Table with no multivalued attributes and unique rows, in 1st
normal form
Note: this is relation, but not a well-structured one
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4848
Anomalies in this TableAnomalies in this Table
 InsertionInsertion–if new product is ordered for order 1007–if new product is ordered for order 1007
of existing customer, customer data must be re-of existing customer, customer data must be re-
entered, causing duplicationentered, causing duplication
 DeletionDeletion–if we delete the Dining Table from Order–if we delete the Dining Table from Order
1006, we lose information concerning this item's1006, we lose information concerning this item's
finish and pricefinish and price
 UpdateUpdate–changing the price of product ID 4 requires–changing the price of product ID 4 requires
update in several recordsupdate in several records
Why do these anomalies exist?
Because there are multiple themes (entity types) in
one relation. This results in duplication and an
unnecessary dependency between the entities
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4949
Second Normal FormSecond Normal Form
 1NF PLUS1NF PLUS every non-key attributeevery non-key attribute
is fully functionally dependent onis fully functionally dependent on
the ENTIRE primary keythe ENTIRE primary key
 Every non-key attribute must be defined byEvery non-key attribute must be defined by
the entire key, not by only part of the keythe entire key, not by only part of the key
 No partial functional dependenciesNo partial functional dependencies
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5050
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
Figure 5-27 Functional dependency diagram for INVOICE
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5151
Partial dependencies are removed, but there
are still transitive dependencies
Getting it intoGetting it into
Second NormalSecond Normal
FormForm
Figure 5-28 Removing partial dependencies
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5252
Third Normal FormThird Normal Form
 2NF PLUS2NF 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 theNote: This is called transitive, because the
primary key is a determinant for anotherprimary key is a determinant for another
attribute, which in turn is a determinant for aattribute, which in turn is a determinant for a
thirdthird
 Solution: Non-key determinant with transitiveSolution: Non-key determinant with transitive
dependencies go into a new table; non-keydependencies go into a new table; non-key
determinant becomes primary key in the newdeterminant becomes primary key in the new
table and stays as foreign key in the old tabletable and stays as foreign key in the old table
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5353
Transitive dependencies are removed
Figure 5-28 Removing partial dependencies
Getting it intoGetting it into
Third NormalThird Normal
FormForm
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5454
Merging RelationsMerging Relations
 View Integration–Combining entities fromView Integration–Combining entities from
multiple ER models into common relationsmultiple ER models into common relations
 Issues to watch out for when merging entitiesIssues to watch out for when merging entities
from different ER models:from different ER models:
 Synonyms–two or more attributes with differentSynonyms–two or more attributes with different
names but same meaningnames but same meaning
 Homonyms–attributes with same name but differentHomonyms–attributes with same name but different
meaningsmeanings
 Transitive dependencies–even if relations are in 3NFTransitive dependencies–even if relations are in 3NF
prior to merging, they may not be after mergingprior to merging, they may not be after merging
 Supertype/subtype relationships–may be hidden priorSupertype/subtype relationships–may be hidden prior
to mergingto merging
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5555
Enterprise KeysEnterprise Keys
 Primary keys that are unique in thePrimary keys that are unique in the
whole database, not just within awhole database, not just within a
single relationsingle relation
 Corresponds with the concept of anCorresponds with the concept of an
object ID in object-oriented systemsobject ID in object-oriented systems
Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5656
Figure 5-31 Enterprise keys
a) Relations with
enterprise key
b) Sample data with
enterprise key

More Related Content

What's hot

Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalizationdaxesh chauhan
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mappingShubham Saini
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
GirdharRatne
 
Database normalization
Database normalizationDatabase normalization
Database normalizationJignesh Jain
 
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMSkoolkampus
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
Vignesh Saravanan
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Oum Saokosal
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMSkoolkampus
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
PadamNepal1
 
DBMS - Normalization
DBMS - NormalizationDBMS - Normalization
DBMS - Normalization
Jitendra Tomar
 
Transaction in DBMS
Transaction in DBMSTransaction in DBMS
Transaction in DBMS
Pyingkodi Maran
 
Normalization PRESENTATION
Normalization PRESENTATIONNormalization PRESENTATION
Normalization PRESENTATION
bit allahabad
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
Vraj Patel
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
Jargalsaikhan Alyeksandr
 
joins in database
 joins in database joins in database
joins in database
Sultan Arshad
 
Data structure
Data structureData structure
Data structureMohd Arif
 
Normalization
NormalizationNormalization
Normalization
Salman Memon
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
darshhingu
 

What's hot (20)

Functional dependencies and normalization
Functional dependencies and normalizationFunctional dependencies and normalization
Functional dependencies and normalization
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mapping
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Database normalization
Database normalizationDatabase normalization
Database normalization
 
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NFDatabase Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
Database Normalization 1NF, 2NF, 3NF, BCNF, 4NF, 5NF
 
14. Query Optimization in DBMS
14. Query Optimization in DBMS14. Query Optimization in DBMS
14. Query Optimization in DBMS
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
DBMS - Normalization
DBMS - NormalizationDBMS - Normalization
DBMS - Normalization
 
Transaction in DBMS
Transaction in DBMSTransaction in DBMS
Transaction in DBMS
 
Enhanced ER(database)
Enhanced ER(database)Enhanced ER(database)
Enhanced ER(database)
 
Normalization PRESENTATION
Normalization PRESENTATIONNormalization PRESENTATION
Normalization PRESENTATION
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 
Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)Database design & Normalization (1NF, 2NF, 3NF)
Database design & Normalization (1NF, 2NF, 3NF)
 
joins in database
 joins in database joins in database
joins in database
 
Data structure
Data structureData structure
Data structure
 
Normalization
NormalizationNormalization
Normalization
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 

Similar to Chap05 c

chapter number 05Corrected local database.ppt
chapter number 05Corrected local database.pptchapter number 05Corrected local database.ppt
chapter number 05Corrected local database.ppt
AzarHamid
 
The Database Environment Chapter 5
The Database Environment Chapter 5The Database Environment Chapter 5
The Database Environment Chapter 5
Jeanie Arnoco
 
Kul 2
Kul 2Kul 2
Kul 2
sw pitara
 
Ch 6 Logical D B Design
Ch 6  Logical D B  DesignCh 6  Logical D B  Design
Ch 6 Logical D B Designguest8fdbdd
 
dbms er model
dbms er modeldbms er model
dbms er model
Surya Swaroop
 
Note Database Chapter2-Part 1.pdf and presentation
Note Database Chapter2-Part 1.pdf and presentationNote Database Chapter2-Part 1.pdf and presentation
Note Database Chapter2-Part 1.pdf and presentation
IqhwanKhairudin1
 
Database Systems - Normalization of Relations(Chapter 4/3)
Database Systems - Normalization of Relations(Chapter 4/3)Database Systems - Normalization of Relations(Chapter 4/3)
Database Systems - Normalization of Relations(Chapter 4/3)
Vidyasagar Mundroy
 
Conceptual Modeling of Data
Conceptual Modeling of DataConceptual Modeling of Data
Conceptual Modeling of Data
M.Zalmai Rahmani
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
Neil Neelesh
 
Unit 2 DBMS
Unit 2 DBMSUnit 2 DBMS
Unit 2 DBMS
DhivyaSubramaniyam
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.modellavya3
 
Test presentation
Test presentationTest presentation
Test presentation
nuvole
 
ER model
ER modelER model
ER model
paddu123
 
Er model
Er modelEr model
Er model
paddu123
 
ER Model and other topics in DBMS
ER Model and other topics in DBMSER Model and other topics in DBMS
ER Model and other topics in DBMS
HarinarayananR2
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraintsKumar
 

Similar to Chap05 c (20)

chapter number 05Corrected local database.ppt
chapter number 05Corrected local database.pptchapter number 05Corrected local database.ppt
chapter number 05Corrected local database.ppt
 
The Database Environment Chapter 5
The Database Environment Chapter 5The Database Environment Chapter 5
The Database Environment Chapter 5
 
Kul 2
Kul 2Kul 2
Kul 2
 
Ch 6 Logical D B Design
Ch 6  Logical D B  DesignCh 6  Logical D B  Design
Ch 6 Logical D B Design
 
dbms er model
dbms er modeldbms er model
dbms er model
 
Note Database Chapter2-Part 1.pdf and presentation
Note Database Chapter2-Part 1.pdf and presentationNote Database Chapter2-Part 1.pdf and presentation
Note Database Chapter2-Part 1.pdf and presentation
 
ch6
ch6ch6
ch6
 
Database Systems - Normalization of Relations(Chapter 4/3)
Database Systems - Normalization of Relations(Chapter 4/3)Database Systems - Normalization of Relations(Chapter 4/3)
Database Systems - Normalization of Relations(Chapter 4/3)
 
Conceptual Modeling of Data
Conceptual Modeling of DataConceptual Modeling of Data
Conceptual Modeling of Data
 
Er
ErEr
Er
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
L7 er2
L7 er2L7 er2
L7 er2
 
Unit 2 DBMS
Unit 2 DBMSUnit 2 DBMS
Unit 2 DBMS
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
 
Test presentation
Test presentationTest presentation
Test presentation
 
dbms
dbmsdbms
dbms
 
ER model
ER modelER model
ER model
 
Er model
Er modelEr model
Er model
 
ER Model and other topics in DBMS
ER Model and other topics in DBMSER Model and other topics in DBMS
ER Model and other topics in DBMS
 
4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
 

Recently uploaded

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 

Recently uploaded (20)

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 

Chap05 c

  • 1. © 2007 by Prentice Hall© 2007 by Prentice Hall 11 Chapter 5:Chapter 5: Logical Database Design andLogical Database Design and the Relational Modelthe Relational Model Modern Database ManagementModern Database Management 88thth EditionEdition Jeffrey A. Hoffer, Mary B. Prescott,Jeffrey A. Hoffer, Mary B. Prescott, Fred R. McFaddenFred R. McFadden
  • 2. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 22 ObjectivesObjectives  Definition of termsDefinition of terms  List five properties of relationsList five properties of relations  State two properties of candidate keysState two properties of candidate keys  Define first, second, and third normal formDefine first, second, and third normal form  Describe problems from merging relationsDescribe problems from merging relations  Transform E-R and EER diagrams to relationsTransform E-R and EER diagrams to relations  Create tables with entity and relational integrityCreate tables with entity and relational integrity constraintsconstraints  Use normalization to convert anomalous tablesUse normalization to convert anomalous tables to well-structured relationsto well-structured relations
  • 3. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 33 RelationRelation  Definition: A relation is a named, two-dimensional table ofDefinition: A relation is a named, two-dimensional table of datadata  Table consists of rows (records) and columns (attribute orTable consists of rows (records) and columns (attribute or field)field)  Requirements for a table to qualify as a relation:Requirements for a table to qualify as a relation:  It must have a unique nameIt must have a unique name  Every attribute value must be atomic (not multivalued, notEvery attribute value must be atomic (not multivalued, not composite)composite)  Every row must be unique (can’t have two rows with exactly theEvery 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: allNOTE: all relationsrelations are inare in 11stst Normal formNormal form
  • 4. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 44 Correspondence with E-RCorrespondence with E-R ModelModel  Relations (tables) correspond with entity typesRelations (tables) correspond with entity types and with many-to-many relationship typesand with many-to-many relationship types  Rows correspond with entity instances and withRows correspond with entity instances and with many-to-many relationship instancesmany-to-many relationship instances  Columns correspond with attributesColumns correspond with attributes  NOTE: The wordNOTE: The word relationrelation (in relational(in relational database) is NOT the same as the worddatabase) is NOT the same as the word relationshiprelationship (in E-R model)(in E-R model)
  • 5. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 55 Key FieldsKey Fields  Keys are special fields that serve two main purposes:Keys are special fields that serve two main purposes:  Primary keysPrimary keys areare uniqueunique identifiers of the relation in question.identifiers of the relation in question. Examples include employee numbers, social security numbers,Examples include employee numbers, social security numbers, etc.etc. This is how we can guarantee that all rows are uniqueThis is how we can guarantee that all rows are unique  Foreign keysForeign keys are identifiers that enable aare identifiers that enable a dependentdependent relationrelation (on the many side of a relationship) to refer to its(on the many side of a relationship) to refer to its parentparent relationrelation (on the one side of the relationship)(on the one side of the relationship)  Keys can beKeys 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 theKeys 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)
  • 6. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 66 Primary Key Foreign Key (implements 1:N relationship between customer and order) Combined, these are a composite primary key (uniquely identifies the order line)…individually they are foreign keys (implement M:N relationship between order and product) Figure 5-3 Schema for four relations (Pine Valley Furniture Company)
  • 7. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 77 Integrity ConstraintsIntegrity Constraints  Domain ConstraintsDomain Constraints  Allowable values for an attribute. See TableAllowable values for an attribute. See Table 5-15-1  Entity IntegrityEntity Integrity  No primary key attribute may be null. AllNo primary key attribute may be null. All primary key fieldsprimary key fields MUSTMUST have datahave data  Action AssertionsAction Assertions  Business rules. Recall from Ch. 4Business rules. Recall from Ch. 4
  • 8. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 88 Domain definitions enforce domain integrity constraints
  • 9. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 99 Integrity ConstraintsIntegrity Constraints  Referential Integrity–rule states that any foreign key value (onReferential Integrity–rule states that any foreign key value (on the relation of the many side) MUST match a primary key valuethe relation of the many side) MUST match a primary key value in the relation of the one side. (Or the foreign key can be null)in the relation of the one side. (Or the foreign key can be null)  For example: Delete RulesFor example: Delete Rules  Restrict–don’t allow delete of “parent” side if related rows exist inRestrict–don’t allow delete of “parent” side if related rows exist in “dependent” side“dependent” side  Cascade–automatically delete “dependent” side rows that correspondCascade–automatically delete “dependent” side rows that correspond with the “parent” side row to be deletedwith the “parent” side row to be deleted  Set-to-Null–set the foreign key in the dependent side to null ifSet-to-Null–set the foreign key in the dependent side to null if deleting from the parent sidedeleting from the parent side  not allowed for weak entitiesnot allowed for weak entities
  • 10. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1010 Figure 5-5 Referential integrity constraints (Pine Valley Furniture) Referential integrity constraints are drawn via arrows from dependent to parent table
  • 11. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1111 Figure 5-6 SQL table definitions Referential integrity constraints are implemented with foreign key to primary key references
  • 12. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1212 Transforming EER DiagramsTransforming EER Diagrams into Relationsinto Relations Mapping Regular Entities to RelationsMapping Regular Entities to Relations 1.1. Simple attributes: E-R attributes map directlySimple attributes: E-R attributes map directly onto the relationonto the relation 2.2. Composite attributes: Use only their simple,Composite attributes: Use only their simple, component attributescomponent attributes 3.3. Multivalued Attribute–Becomes a separateMultivalued Attribute–Becomes a separate relation with a foreign key taken from therelation with a foreign key taken from the superior entitysuperior entity
  • 13. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1313 (a) CUSTOMER entity type with simple attributes Figure 5-8 Mapping a regular entity (b) CUSTOMER relation
  • 14. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1414 (a) CUSTOMER entity type with composite attribute Figure 5-9 Mapping a composite attribute (b) CUSTOMER relation with address detail
  • 15. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1515 Figure 5-10 Mapping an entity with a multivalued attribute One–to–many relationship between original entity and new relation (a) Multivalued attribute becomes a separate relation with foreign key (b)
  • 16. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1616 Transforming EER DiagramsTransforming EER Diagrams into Relations (cont.)into Relations (cont.) Mapping Weak EntitiesMapping Weak Entities  Becomes a separate relation with aBecomes a separate relation with a foreign key taken from the superiorforeign key taken from the superior entityentity  Primary key composed of:Primary key composed of:  Partial identifier of weak entityPartial identifier of weak entity  Primary key of identifying relation (strongPrimary key of identifying relation (strong entity)entity)
  • 17. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1717 Figure 5-11 Example of mapping a weak entity a) Weak entity DEPENDENT
  • 18. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1818 NOTE: the domain constraint for the foreign key should NOT allow null value if DEPENDENT is a weak entity Foreign key Composite primary key Figure 5-11 Example of mapping a weak entity (cont.) b) Relations resulting from weak entity
  • 19. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 1919 Transforming EER DiagramsTransforming EER Diagrams into Relations (cont.)into Relations (cont.) Mapping Binary RelationshipsMapping Binary Relationships  One-to-Many–Primary key on the one sideOne-to-Many–Primary key on the one side becomes a foreign key on the many sidebecomes a foreign key on the many side  Many-to-Many–Create aMany-to-Many–Create a new relationnew relation withwith the primary keys of the two entities as itsthe primary keys of the two entities as its primary keyprimary key  One-to-One–Primary key on the mandatoryOne-to-One–Primary key on the mandatory side becomes a foreign key on the optionalside becomes a foreign key on the optional sideside
  • 20. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2020 Figure 5-12 Example of mapping a 1:M relationship a) Relationship between customers and orders Note the mandatory one b) Mapping the relationship Again, no null value in the foreign key…this is because of the mandatory minimum cardinality Foreign key
  • 21. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2121 Figure 5-13 Example of mapping an M:N relationship a) Completes relationship (M:N) The Completes relationship will need to become a separate relation
  • 22. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2222 New intersection relation Foreign key Foreign key Composite primary key Figure 5-13 Example of mapping an M:N relationship (cont.) b) Three resulting relations
  • 23. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2323 Figure 5-14 Example of mapping a binary 1:1 relationship a) In_charge relationship (1:1) Often in 1:1 relationships, one direction is optional.
  • 24. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2424 b) Resulting relations Figure 5-14 Example of mapping a binary 1:1 relationship (cont.) Foreign key goes in the relation on the optional side, Matching the primary key on the mandatory side
  • 25. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2525 Transforming EER DiagramsTransforming EER Diagrams into Relations (cont.)into Relations (cont.) Mapping Associative EntitiesMapping Associative Entities  Identifier Not AssignedIdentifier Not Assigned  Default primary key for the associationDefault primary key for the association relation is composed of the primary keys ofrelation is composed of the primary keys of the two entities (as in M:N relationship)the two entities (as in M:N relationship)  Identifier AssignedIdentifier Assigned  It is natural and familiar to end-usersIt is natural and familiar to end-users  Default identifier may not be uniqueDefault identifier may not be unique
  • 26. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2626 Figure 5-15 Example of mapping an associative entity a) An associative entity
  • 27. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2727 Figure 5-15 Example of mapping an associative entity (cont.) b) Three resulting relations Composite primary key formed from the two foreign keys
  • 28. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2828 Figure 5-16 Example of mapping an associative entity with an identifier a) SHIPMENT associative entity
  • 29. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 2929 Figure 5-16 Example of mapping an associative entity with an identifier (cont.) b) Three resulting relations Primary key differs from foreign keys
  • 30. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3030 Transforming EER DiagramsTransforming EER Diagrams into Relations (cont.)into Relations (cont.) Mapping Unary RelationshipsMapping Unary Relationships  One-to-Many–Recursive foreign key in theOne-to-Many–Recursive foreign key in the same relationsame relation  Many-to-Many–Two relations:Many-to-Many–Two relations:  One for the entity typeOne for the entity type  One for an associative relation in which theOne for an associative relation in which the primary key has two attributes, both takenprimary key has two attributes, both taken from the primary key of the entityfrom the primary key of the entity
  • 31. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3131 Figure 5-17 Mapping a unary 1:N relationship (a) EMPLOYEE entity with unary relationship (b) EMPLOYEE relation with recursive foreign key
  • 32. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3232 Figure 5-18 Mapping a unary M:N relationship (a) Bill-of-materials relationships (M:N) (b) ITEM and COMPONENT relations
  • 33. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3333 Transforming EER DiagramsTransforming EER Diagrams into Relations (cont.)into Relations (cont.) Mapping Ternary (and n-ary)Mapping Ternary (and n-ary) RelationshipsRelationships  One relation for each entity and oneOne relation for each entity and one for the associative entityfor the associative entity  Associative entity has foreign keysAssociative entity has foreign keys to each entity in the relationshipto each entity in the relationship
  • 34. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3434 Figure 5-19 Mapping a ternary relationship a) PATIENT TREATMENT Ternary relationship with associative entity
  • 35. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3535 b) Mapping the ternary relationship PATIENT TREATMENT Remember that the primary key MUST be unique Figure 5-19 Mapping a ternary relationship (cont.) This is why treatment date and time are included in the composite primary key But this makes a very cumbersome key… It would be better to create a surrogate key like Treatment#
  • 36. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3636 Transforming EER DiagramsTransforming EER Diagrams into Relations (cont.)into Relations (cont.) Mapping Supertype/Subtype RelationshipsMapping Supertype/Subtype Relationships  One relation for supertype and for each subtypeOne relation for supertype and for each subtype  Supertype attributes (including identifier andSupertype attributes (including identifier and subtype discriminator) go into supertype relationsubtype discriminator) go into supertype relation  Subtype attributes go into each subtype;Subtype attributes go into each subtype; primary key of supertype relation also becomesprimary key of supertype relation also becomes primary key of subtype relationprimary key of subtype relation  1:1 relationship established between supertype1:1 relationship established between supertype and each subtype, with supertype as primaryand each subtype, with supertype as primary tabletable
  • 37. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3737 Figure 5-20 Supertype/subtype relationships
  • 38. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3838 Figure 5-21 Mapping Supertype/subtype relationships to relations These are implemented as one-to-one relationships
  • 39. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 3939 Data NormalizationData Normalization  Primarily a tool to validate and improvePrimarily a tool to validate and improve a logical design so that it satisfiesa logical design so that it satisfies certain constraints thatcertain constraints that avoidavoid unnecessary duplication ofunnecessary duplication of datadata  The process of decomposing relationsThe process of decomposing relations with anomalies to produce smaller,with anomalies to produce smaller, well-structuredwell-structured relationsrelations
  • 40. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4040 Well-Structured RelationsWell-Structured Relations  A relation that contains minimal data redundancy andA relation that contains minimal data redundancy and allows users to insert, delete, and update rowsallows users to insert, delete, and update rows without causing data inconsistencieswithout causing data inconsistencies  Goal is to avoid anomaliesGoal is to avoid anomalies  Insertion AnomalyInsertion Anomaly –adding new rows forces user to create–adding new rows forces user to create duplicate dataduplicate 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
  • 41. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4141 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
  • 42. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4242 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 classinformation about the existence of a Tax Acc class  ModificationModification–giving a salary increase to employee–giving a salary increase to employee 100 forces us to update multiple records100 forces us to update multiple records Why do these anomalies exist? Because there are two themes (entity types) in this one relation. This results in data duplication and an unnecessary dependency between the entities
  • 43. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4343 Functional Dependencies and KeysFunctional Dependencies and Keys  Functional Dependency: The value ofFunctional Dependency: The value of one attribute (theone attribute (the determinantdeterminant)) determines the value of anotherdetermines the value of another attributeattribute  Candidate Key:Candidate Key:  A unique identifier. One of the candidateA unique identifier. One of the candidate keys will become the primary keykeys will become the primary key  E.g. perhaps there is both credit card numberE.g. perhaps there is both credit card number and SS# in a table…in this case both areand SS# in a table…in this case both are candidate keyscandidate keys  Each non-key field is functionallyEach non-key field is functionally dependent on every candidate keydependent on every candidate key
  • 44. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4444 Figure 5.22 Steps in normalization
  • 45. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4545 First Normal FormFirst Normal Form  No multivalued attributesNo multivalued attributes  Every attribute value is atomicEvery attribute value is atomic  Fig. 5-25Fig. 5-25 is notis not in 1in 1stst Normal FormNormal Form (multivalued attributes)(multivalued attributes)  it is not ait is not a relationrelation  Fig. 5-26Fig. 5-26 isis in 1in 1stst Normal formNormal form  All relationsAll relations are in 1are in 1stst NormalNormal FormForm
  • 46. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4646 Table with multivalued attributes, not in 1st normal form Note: this is NOT a relation
  • 47. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4747 Table with no multivalued attributes and unique rows, in 1st normal form Note: this is relation, but not a well-structured one
  • 48. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4848 Anomalies in this TableAnomalies in this Table  InsertionInsertion–if new product is ordered for order 1007–if new product is ordered for order 1007 of existing customer, customer data must be re-of existing customer, customer data must be re- entered, causing duplicationentered, causing duplication  DeletionDeletion–if we delete the Dining Table from Order–if we delete the Dining Table from Order 1006, we lose information concerning this item's1006, we lose information concerning this item's finish and pricefinish and price  UpdateUpdate–changing the price of product ID 4 requires–changing the price of product ID 4 requires update in several recordsupdate in several records Why do these anomalies exist? Because there are multiple themes (entity types) in one relation. This results in duplication and an unnecessary dependency between the entities
  • 49. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 4949 Second Normal FormSecond Normal Form  1NF PLUS1NF PLUS every non-key attributeevery non-key attribute is fully functionally dependent onis fully functionally dependent on the ENTIRE primary keythe ENTIRE primary key  Every non-key attribute must be defined byEvery non-key attribute must be defined by the entire key, not by only part of the keythe entire key, not by only part of the key  No partial functional dependenciesNo partial functional dependencies
  • 50. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5050 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 Figure 5-27 Functional dependency diagram for INVOICE
  • 51. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5151 Partial dependencies are removed, but there are still transitive dependencies Getting it intoGetting it into Second NormalSecond Normal FormForm Figure 5-28 Removing partial dependencies
  • 52. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5252 Third Normal FormThird Normal Form  2NF PLUS2NF 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 theNote: This is called transitive, because the primary key is a determinant for anotherprimary key is a determinant for another attribute, which in turn is a determinant for aattribute, which in turn is a determinant for a thirdthird  Solution: Non-key determinant with transitiveSolution: Non-key determinant with transitive dependencies go into a new table; non-keydependencies go into a new table; non-key determinant becomes primary key in the newdeterminant becomes primary key in the new table and stays as foreign key in the old tabletable and stays as foreign key in the old table
  • 53. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5353 Transitive dependencies are removed Figure 5-28 Removing partial dependencies Getting it intoGetting it into Third NormalThird Normal FormForm
  • 54. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5454 Merging RelationsMerging Relations  View Integration–Combining entities fromView Integration–Combining entities from multiple ER models into common relationsmultiple ER models into common relations  Issues to watch out for when merging entitiesIssues to watch out for when merging entities from different ER models:from different ER models:  Synonyms–two or more attributes with differentSynonyms–two or more attributes with different names but same meaningnames but same meaning  Homonyms–attributes with same name but differentHomonyms–attributes with same name but different meaningsmeanings  Transitive dependencies–even if relations are in 3NFTransitive dependencies–even if relations are in 3NF prior to merging, they may not be after mergingprior to merging, they may not be after merging  Supertype/subtype relationships–may be hidden priorSupertype/subtype relationships–may be hidden prior to mergingto merging
  • 55. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5555 Enterprise KeysEnterprise Keys  Primary keys that are unique in thePrimary keys that are unique in the whole database, not just within awhole database, not just within a single relationsingle relation  Corresponds with the concept of anCorresponds with the concept of an object ID in object-oriented systemsobject ID in object-oriented systems
  • 56. Chapter 5 © 2007 by Prentice Hall© 2007 by Prentice Hall 5656 Figure 5-31 Enterprise keys a) Relations with enterprise key b) Sample data with enterprise key