Title: Cost Management Systems
1AGENDA
- Today-
- Relational Data Models
- Transforming the ER diagram
- In-class Problem 3
- Data Normalization
- Some examples
2 EXAMPLE
- Pipefitters Supply Company accepts orders that
includes the customers name and a list of
inventory items that that the customer wishes to
purchase. This inventory list includes the
quantity of each inventory item and the price . - A sale order can have only one customer each and
can each have many inventory items and each
inventory item can appear on many sales orders.
3Relational DATA Model
- Three components
- Data structure.
- Data organized as tables
- Data manipulation.
- Operations to manipulate data
- Data integrity
- Facilities to specify business rules that
preserves integrity when data is manipulated
4Relational Definitions
- Relation
- Named two dimensional table of data
- Every relation has a unique name.
- Every attribute (column) value is single-valued.
- Every row is unique.
- Attributes in tables have unique names.
- The order of the columns is irrelevant.
- The order of the rows is irrelevant.
5Relational Keys and Structures
- Primary Key-unique identifier
- Composite Key- consists of more than one
attribute - Foreign Key-serves as a primary key in some other
table - One-to-Many Relationship
- Many-to-Many Relationship
6Pine Valley Furniture Company
7Schema for four relations
8Instance of a relational schema
9Integrity Constraints
- Domain Constraints
- Allowable values for an attribute.
- Entity Integrity
- No primary key attribute may be null.
- Referential Integrity
- Foreign key must match another relations primary
key or be null - Operational Constraints
- Business rules.
10Referential integrity constraints
11Transforming E-R Diagrams into Relations
- Map Regular Entities to Relations
- Composite attributes Use only their simple,
component attributes - Multi-valued Attribute - Becomes a separate
relation - 2. Map Weak Entities
- Becomes a separate relation with a foreign key
taken from the identifying relation
12Mapping a composite attribute
CUSTOMER entity type with composite attribute
13Example of mapping a weak entity
Weak entity DEPENDENT
14Relations resulting from weak entity
15Transforming E-R Diagrams Into Relations
- What about multi-valued attributes?
- 3. Map Binary Relationships
- One-to-Many - Primary key on the one side becomes
a foreign key on the many side. - Many-to-Many - Create a new relation with the
primary keys of the two entities as its primary
key. - One-to-One - Primary key on the mandatory side
becomes a foreign key on the optional side .
16Example of mapping a 1M relationship
Relationship between customers and orders
17M
Mapping the relationship
18Example of mapping an MN relationship
Requests relationship (MN)
19 Three resulting relations
20Mapping a binary 11 relationship
Binary 11 relationship
21Resulting relations
22Transforming E-R Diagrams Into Relations
- 4. Map Associative Entities
- Default primary key for the association relation
is the primary keys of the two entities.
23Mapping an associative entity with an identifier
Associative entity (SHIPMENT)
24Three relations
25Transforming E-R Diagrams Into Relations
- 5. Map Unary Relationships
- One-to-Many - Recursive foreign key in the same
relation. - Many-to-Many - Bill-of-materials Two relations
- One for the entity type.
- One for an associative relation in which the
primary key has two attributes, both taken from
the primary key of the entity. - 6. Map Ternary (and n-ary) Relationships
- One relation for each entity and one for the
associative entity.
26Mapping a ternary relationship
Ternary relationship with associative entity
27 Mapping the ternary relationship
28Supertype/Subtype Relationships
29Mapping Supertype/Subtype relationships
to relations
30Data Normalization
- Primarily a tool to validate and improve a
logical design so that it satisfies certain
constraints that avoid unnecessary duplication of
data. - The process of decomposing relations to produce
smaller, well-structured relations.
31Steps in Normalization
32Normalization
- Normalization is accomplished in stages
- Apply rules regarding functional dependencies
(the relationships between attributes) - First Normal Form
- No multi-valued attributes (No rows containing
two or more values for a SINGLE attribute)
33Second Normal Form
- 1NF and no partial functional dependencies. Every
non-key attribute depends FULLY on the entire
primary key only - Exampleno entries such as
- First Last Stud Course Grade
- Bill Jones 100 math101 A
- Bill Jones 100 math201 A
- Note that here the primary key is Student
Course and Last depends only on the Student not
the Course (only part of the primary key).
34Third Normal Form
- 2NF and no transitive dependencies (functional
dependency between non-key attributes.)
35Removing a transitive dependency
Decomposing the SALES relation
36 Relations in 3NF