may 8 more on data modeling. types of entities fundamental entity regular rectangle (exist by...
Post on 19-Dec-2015
222 views
TRANSCRIPT
![Page 1: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/1.jpg)
May 8May 8
More on Data ModelingMore on Data Modeling
![Page 2: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/2.jpg)
Types of Entities
Fundamental Entityregular rectangle (exist by themselves)
Attributive Entity only exists because of the existence of some other entity
Associative Entity result from many to many relationship
![Page 3: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/3.jpg)
Many to Many relationships are not stable
Student CourseRegistersfor
JohnAhmedMaryNganSteve
CS211CS212CS255IS315
![Page 4: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/4.jpg)
Solution
JohnAhmedMaryNganSteve
CS211CS212CS255IS315
Student Registration Course
![Page 5: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/5.jpg)
ERD Concepts
AttributeA characteristic of an entity or relationship
Primary Key• Simple• Composite or concatenated
Nonkey• These are all of the other attributes
Multivalued• May contain two or more values• We use an Attributive Entity to resolve these
![Page 6: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/6.jpg)
ERD Concepts
AttributeA characteristic of an entity or relationship
Primary Key• Simple• Composite or concatenated
Nonkey• These are all of the other attributes
Multivalued• May contain two or more values• We use an Attributive Entity to resolve these
Foreign Keys• Pointers to a record in another entity
![Page 7: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/7.jpg)
Primary Key
Attribute
Multivalued Attribute
![Page 8: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/8.jpg)
Attributes
Atomic Factcannot have attributes of its own
Single Valuecannot have more than one value
Persons Last_nameFirst_name
![Page 9: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/9.jpg)
Some Attributes
Persons
Last_name
First_name
Address
![Page 10: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/10.jpg)
Some Attributes
Persons
Last_name
First_name
Street
City
State
Zip
Last_name
First_name
Street
City
State
Zip
![Page 11: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/11.jpg)
Same data shown as a table
FName
LName
Street City State
Zip
Steve Kerr 2 Main Lisle IL 60601
Tom Mix 7 Oak LA CA 97654
Jason Jones 3 Elm SF CA 92345
PERSONS
ID#
123
345
564
PERSONS
![Page 12: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/12.jpg)
Marriage is an M:N proposition
Personsis
marriedto
![Page 13: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/13.jpg)
Notice the functional dependency
Personsis
marriedto
marriage_date
![Page 14: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/14.jpg)
Date becomes an attribute of the relation
Personsmarriage
_date
is married
toMarriage
![Page 15: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/15.jpg)
Functional Dependence
For a relation R, attribute A is functionally dependent of attribute B if, for every valid instance, the value of B determines the value of A.
We draw this as:B --> A
In English, what all this means is…
![Page 16: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/16.jpg)
Suppose we have a sales relation:
Year Sales (millions)
1998 $32.41999 $33.62000 $29.42001 $33.5
Then, Year --> Sales
$33.6
![Page 17: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/17.jpg)
Date becomes an attribute of the relation
Personsmarriage
_date
is married
toMarriage
![Page 18: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/18.jpg)
Student ClassRoster
Student(Student-ID, StudentLName, StudentFName, Address, Phone)Class(Department, Course-ID, Section-ID, Semester, Year, CourseTitle, Credits)Roster(Student-ID, Department, Course-ID, Section-ID, Semester, Year, Grade)
Student-ID
StudentLName
StudentFName
Address Phone
120453 Smith Tom 333 Main 445-2321
443645 Jones Tom 234 Pine 456-7632
347654 Jones Fred 123 Oak 232-9543
298764 Jones Mary 123 Oak 232-9543
Dept CourseID SectionID
Semester
Year Course Title
Credit
IS 315 803 Winter 2002 SA&D 4
IS 315 807 Winter 2002 SA&D 4
IS 315 807 Spring 2002 SA&D 4
Student-ID
Dept CourseID
SectionID
Semester
Year Grade
120453 IS 315 803 Winter 2002 A-
443645 IS 315 807 Winter 2002 B+
347654 IS 315 803 Winter 2002 A
298764 IS 315 803 Winter 2002 A-
![Page 19: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/19.jpg)
DePaul UniversityGrade ReportFall Semester 1998
Name: James Jordan ID: 123456789Address: 1201 Peach DriveMajor: IS
Instructor InstructorCourse ID Title Name Location GradeIS 315 SA&D Valacich CST 440B A-IS 512 Groupware Tyran CST 430G B+
What are the functional dependencies on this report?
![Page 20: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/20.jpg)
Student # Course #CourseTitle
InstructorInstructorLocation
Grade
A123 IS315 SA & D Valacich CST440B A-
O459 IS512 Groupware Tyran CST430G B+
L889 CS319 Database Gilson CST712 C-
Course Roster
![Page 21: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/21.jpg)
KeysPrimary KeysForeign KeysHow keys work in Associative EntitiesHow keys work in Attributive Entities
![Page 22: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/22.jpg)
Business rule: each customer has one sales rep, but sales reps can sell to many customers.
SNum Sname
S12 Tom
S13 Dick
S14 Harry CNum CName
C7 Huey
C8 Dewey
C9 Louis
?
?
![Page 23: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/23.jpg)
Business rule: each customer has one sales rep, but sales reps can sell to many customers.
SNum Sname
S12 Tom
S13 Dick
S14 Harry CNum CName
C7 Huey
C8 Dewey
C9 Louis
For each salesman there can be many customers; for each customer there is only one salesman.
![Page 24: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/24.jpg)
Business rule: each customer has one sales rep, but sales reps can sell to many customers.
SNum Sname
S12 Tom
S13 Dick
S14 Harry CNum CName SNum [fk]
C7 Huey S12
C8 Dewey S12
C9 Louis S14
For each salesman there can be many customers; for each customer there is only one salesman.
![Page 25: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/25.jpg)
Business rule: each customer has one sales rep, but sales reps can sell to many customers.
SNum Sname CNum
S12 Tom C7
S12 Tom C8
S13 Dick
S14 Harry C9 CNum CName
C7 Huey
C8 Dewey
C9 Louis
For each salesman there can be many customers; for each customer there is only one salesman.
![Page 26: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/26.jpg)
NEW Business rule: each customer has one sales rep, and each sales rep has only one customer.
SNum Sname CNum
S12 Tom C8
S13 Dick C7
S14 Harry C9 CNum CName SNum [fk]
C7 Huey S13
C8 Dewey S12
C9 Louis S14
For each salesman there is only one customer; for each customer there is only one salesman.
![Page 27: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/27.jpg)
Review of the rules
KeysPrimary Keys•Every record has a unique primary key
Foreign Keys• In a 1:M relationship, the M side always
has the FK• In a 1:1 relationship, both sides have FKs
How keys work in Associative EntitiesHow keys work in Attributive Entities
![Page 28: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/28.jpg)
Business rule: customers can buy from many salesmen; salesmen can sell to many customers.
SNum Sname
S12 Tom
S13 Dick
S14 Harry
CNum CName
C7 Huey
C8 Dewey
C9 Louis
In order to produce an efficient and stable database, this requires an Associative Entity
![Page 29: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/29.jpg)
Business rule: customers can buy from many salesmen; salesmen can sell to many customers.
SNum Sname
S12 Tom
S13 Dick
S14 Harry
CNum CName
C7 Huey
C8 Dewey
C9 Louis
For each customer there can be many transactions; for each transaction there is only one customer; for each salesman there can be many transactions; for each transaction there is only one salesman.
SNum CNum
Date Prod
Qu
S12 C9 5/8/02 P2 4
S13 C7 5/9/02 P2 5
S14 C8 6/1/02 P3 2
S12 C7 6/3/02 P6 7
![Page 30: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/30.jpg)
Business rule: each order can have many order items
SNum CNum
Date Prod Qu
S12 C9 5/8/02 P2 4
S13 C7 5/9/02 P2 5
S13 C7 5/9/02 P3 2
S12 C7 6/3/02 P6 7
In order to produce an efficient and stable database, this requires an Attributive Entity
![Page 31: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/31.jpg)
Business rule: each order can have many order items
SNum CNum
Date
S12 C9 5/8/02
S13 C7 5/9/02
S12 C7 6/3/02
SNum CNum Line Prod Qu
S12 C9 1 P2 4
S13 C7 1 P2 5
S13 C7 2 P3 2
S12 C7 1 P6 7
In order to produce an efficient and stable database, this requires an Attributive Entity
![Page 32: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/32.jpg)
Purchase OrderAcme Equipment Company
Butte, Montana 87654
PO#:
Date
Address
City, State, Zip
Phone
Customer
Unit PriceProduct# Product Description Quantity Total Price
6
5
4
3
2
1
Line #
$Order Total
Acme Equipment sells product using the purchase orders (Pos) shown at left. Draw the ERD that this PO suggests. Make sure to indicate your Primary and Foreign Keys and assign fields for each entity.
![Page 33: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/33.jpg)
Review of the rules
KeysPrimary Keys
• Every record has a unique primary keyForeign Keys
• In a 1:M relationship, the M side always has the FK• In a 1:1 relationship, both sides have FKs
How keys work in Associative Entities• The Associative Entity takes the many side of all
1:M relationships. The key of the Associative Entity is a compound key of all primary entities.
How keys work in Attributive Entities• The Attributive Entity is the many side of the 1:M
relationship. The Attributive Entity has a compound key comprised of the key of the primary entity plus a unique marker of the attribute.
![Page 34: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/34.jpg)
How do you build an ERD for your case project?
How do you build an ERD for your case project?
Here is a cookbook approachHere is a cookbook approach
![Page 35: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/35.jpg)
Cookbook 1
Derive a high level, first cut data model
What are the techniques?• look at forms, look at existing database,
Identify data entitiesWhat are the entities of interest around which data must be stored?“Model the world” be more rather than less comprehensiveBe aware of the domain you are exploring
![Page 36: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/36.jpg)
Requirements Determination Questions for Data Modeling
What people, places, and things are used in the business? How many of each are there? How do you differentiate them? Entities and attributes What unique characteristics distinguish one object from another? Attributes and primary keyWhat characteristics describe each object? Attributes and secondary keys
![Page 37: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/37.jpg)
Requirements Determination Questions for Data Modeling
How do you use the data? What is the source of the data? Who controls it?Over what time periods are you interested in this data? If it changes over time, do you need to know that? Cardinality and time issuesWhat kinds of transactions do you keep track of? Relationships
![Page 38: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/38.jpg)
Requirements Determination Questions for Data Modeling
Are transactions always handled the same way, or are there sometimes exceptions? Can only some of the attributes of an object change? CardinalityCan the associations or relationships among objects change over time?
![Page 39: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/39.jpg)
ERD Data Sources
Data entry forms (paper and screen)Reports (paper and screen)Existing DatabasesInterviews
![Page 40: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/40.jpg)
Cookbook 2
Identify likely attributes of those entities
• What are the keys? (Primary, Alternate, Foreign)
• How should you name them?• Determine constraints (cardinalities) of
attributes
Determine relationships among entities• How are they related? Optional or mandatory?• What are the cardinalities of the relationships?• Fundamental, attributive, and associative
entities
![Page 41: May 8 More on Data Modeling. Types of Entities Fundamental Entity regular rectangle (exist by themselves) Attributive Entity only exists because of the](https://reader035.vdocuments.net/reader035/viewer/2022062421/56649d3a5503460f94a14817/html5/thumbnails/41.jpg)
Cookbook 3
Balance the model into 1:N relationshipsFor each 1:1 relationship
• determine whether the 2 entities are truly separate, or can be combined
M:N relationships • can always be split into 1:N relationships by
discovering the associative entity
For each 1:N relationship• analyze whether there is dependency
– Is one entity dependent on the other, or are they independent?