Upload
bethanie-carroll
View
225
Download
0
Tags:
Embed Size (px)
Citation preview
INTRODUCTION TO DATA MODELINGCS 260
Database Systems
Overview
Introduction to data models Entity-relationship (E-R) model
components Entities Attributes Relationships
Introduction to Data Models
A data model is a precise description of the data to be contained in a system
Data model levels: Conceptual, Logical, Physical Conceptual
Describes the data contained by a system at a high level
Focuses on the data entities and their relationships Design should be independent of storage mechanism
(e.g. database) Should be general enough to apply to multiple logical
models
Introduction to Data Models
Data model levels (continued) Logical
Describes the data contained by a system in more detail Application of the conceptual model on a particular storage
mechanism (e.g. relational database) Should be general enough to apply to multiple physical
models For relational databases, the logical model may be very
similar to the conceptual model Physical
Describes the data contained by a system with the most detail Application of the logical model on a specific implementation
of a particular storage mechanism (e.g. Oracle relational database)
Implemented for relational databases using DDL
Introduction to Data Models
Why create data models? Data models aid in the development of a complete,
sound database design that does not contain redundant data values which can become inconsistent
Examples of redundant data on the next slide What happens if a department changes its name or gets a
new manager? Are there any problems with this data already?
What happened with Joyce A. English? What happened with Product X? If EMPLOYEE_PROJECTS is the only place where a project’s
name and location are associated, what happens if Franklin T. Wong quits?
Introduction to Data ModelsEMPLOYEE (SSN, Ename, Bdate, Address, Dnumber, Dname, DMgrSSN) SSN EName Bdate Address Dnumber DName DMgrSSN 123456789 Smith, John B. 09-Jan-55 731 Fondren, Houston,
TX 5 Research 333445555
333445555 Wong, Franklin T. 08-Dec-45 638 Voss, Houston, TX 5 Research 333444555 999887777 Zelaya, Alicia J. 19-Jul-61 3321 Castle, Spring, TX 4 Administration 987654321 987654321 Wallace, Jennifer S. 19-Jun-31 291 Berry, Bellaire, TX 4 Administration 987654321 666884444 Narayan Ramesh K.. 15-Sep-52 975 FireOak, Humble,
TX 5 Research 333445555
453453453 English, Joyce A. 31-Jun-62 5631 Rice, Houston, TX 5 Research 333445555 987987987 Jabbar, Ahmad V. 29-Mar-59 980 Dallas, Houston, TX 4 Administration 987654321 888665555 Borg, James E. 10-Nov-27 450 Stone, Houston, TX 1 Headquarters 888665555
EMPLOYEE-PROJECTS (SSN, ProjNumber, Hours, ProjName, ProjLoc) SSN EName ProjNumber Hours ProjName ProjLocation 123456789 Smith, John B. 1 32.5 ProductX Stafford 123456789 Smith, John B. 2 7.5 ProductY Sugarland 666884444 Narayan, Ramesh K. 3 40.0 ProductZ Houston 453453453 English, Joyce A. 1 20.0 ProductX Bellaire 453453453 Meadows, Joyce A. 2 20.0 ProductY Sugarland 333445555 Wong, Frank 2 10.0 ProductY Bellaire 333445555 Wong, Frank 3 10.0 ProductZ Houston 333445555 Wong, Franklin T. 10 10.0 Computerization Stafford 333445555 Wong, Franklin T. 20 10.0 Reorganization Houston
Overview
Introduction to data models Entity-relationship (E-R) model
components Entities Attributes Relationships
Entity-Relationship Models
This classic data model addresses data and the relationships between that data Developed to facilitate database design Many extensions and variations exist
Components Entities Attributes Relationships
Overview
Introduction to data models Entity-relationship (E-R) model
components Entities Attributes Relationships
Entities
Entity An entity is a “thing” or “object” in the real
world that is distinguishable from all other objects
Similar to a Java class Examples
Customer Product
Naming conventions Use short, singular, descriptive names Logical models for a relational database should use
names that consist of multiple words and be unique
Entities
Entity instance A specific occurrence of an entity Similar to a Java object An entity must have multiple entity
instances Examples
The customer identified by “Bobby Bon Bons” The product identified by “Celestial Cashew
Crunch”
Overview
Introduction to data models Entity-relationship (E-R) model
components Entities Attributes Relationships
Attributes
Attribute An attribute is a descriptive property
possessed by each entity instance Examples
Name Price
Naming conventions Use short, descriptive names Logical models for relational databases should
use names that consist of multiple words and are appropriately unique
Attributes
Attribute value An attribute value is the value of a
particular attribute for a particular entity instance
Examples Bobby Bon Bons 1.5
If an attribute’s value uniquely identifies an entity instance, then that attribute is a key
Attributes
Attribute characteristics Atomic (simple) vs. composite
Atomic: cannot be reasonably divided into subparts
Composite: can be reasonably divided into subparts
Examples Atomic: 105 Garfield Ave. Composite: 105 Garfield Ave., Eau Claire, WI 54701
Attributes
Attribute characteristics Single-valued vs. multivalued
Single-valued: always only one attribute value per attribute
Multivalued: multiple attribute values per attribute possible
Examples Phone number: (555) 123-4567 Phone numbers: (555) 123-4567, (555) 987-6543
Attributes
Attribute characteristics Derived
A derived attribute is one who’s value can be inferred from the value of other attributes or entities
Example Age can be inferred if a date of birth attribute is
present for the associated entity
Overview
Introduction to data models Entity-relationship (E-R) model
components Entities Attributes Relationships
Relationships
Relationship A relationship is an association among
entities Entities “participate” in relationships
A relationship may also have attributes An entity may have a specified “role” that
indicates how that entity participates in the relationship
Examples A customer has a customer type A purchase consists of a customer and a product
Relationships
Relationship constraints Cardinalities
Cardinalities express the number of entity instances that participate in a relationship
Types One-to-one (1:1) One-to-many (1:M) Many-to-many (M:M)
Relationships
Cardinality types One-to-one (1:1)
An entity instance A is associated with at most one entity instance B, and an entity instance B is associated with at most one entity instance A
Example In a system that has an Employee entity and a
Spouse entity, a 1:1 relationship exists between them
An employee can have at most one spouse, and a spouse can be associated with at most one employee
Are there any 1:1 relationships in our candy database?
Sample Database (CANDY)CUST_ID CUST_NAME CUST_TYPE CUST_ADDR CUST_ZIP CUST_PHONE USERNAME PASSWORD
1 Jones, Joe P 1234 Main St. 91212 434-1231 jonesj 12342 Armstrong,Inc. R 231 Globe Blvd. 91212 434-7664 armstrong 33333 Sw edish Burgers R 1889 20th N.E. 91213 434-9090 sw edburg 23534 Pickled Pickles R 194 CityView 91289 324-8909 pickpick 53335 The Candy Kid W 2121 Main St. 91212 563-4545 kidcandy 23516 Waterman, Al P 23 Yankee Blvd. 91234 w ateral 89007 Bobby Bon Bons R 12 Nichi Cres. 91212 434-9045 bobbybon 30118 Crow sh, Elias P 7 77th Ave. 91211 434-0007 crow el 10339 Montag, Susie P 981 Montview 91213 456-2091 montags 9633
10 Columberg Sw eets W 239 East Falls 91209 874-9092 columsw e 8399
PURCH_ID PROD_ID CUST_ID PURCH_DATE DELIVERY_DATE POUNDS STATUS
1 1 5 28-Oct-04 28-Oct-04 3.5 PAID2 2 6 28-Oct-04 30-Oct-04 15 PAID3 1 9 28-Oct-04 28-Oct-04 2 PAID3 3 9 28-Oct-04 28-Oct-04 3.7 PAID4 3 2 28-Oct-04 3.7 PAID5 1 7 29-Oct-04 29-Oct-04 3.7 NOT PAID5 2 7 29-Oct-04 29-Oct-04 1.2 NOT PAID5 3 7 29-Oct-04 29-Oct-04 4.4 NOT PAID6 2 7 29-Oct-04 3 PAID7 2 10 29-Oct-04 14 NOT PAID7 5 10 29-Oct-04 4.8 NOT PAID8 1 4 29-Oct-04 29-Oct-04 1 PAID8 5 4 29-Oct-04 7.6 PAID9 5 4 29-Oct-04 29-Oct-04 3.5 NOT PAID
PROD_ID PROD_DESC PROD_COSTPROD_PRICE
1 Celestial Cashew Crunch 7.45$ 10.00$
2 Unbrittle Peanut Paradise 5.75$ 9.00$
3 Mystery Melange 7.75$ 10.50$
4 Millionaire’s Macadamia Mix 12.50$ 16.00$
5 Nuts Not Nachos 6.25$ 9.50$
CUST_TYPE_IDCUST_TYPE_DESC
P Private
R Retail
W Wholesale
CANDY_CUSTOMER
CANDY_PURCHASE
CANDY_CUST_TYPE
CANDY_PRODUCT
Relationships
Cardinality types One-to-many (1:M)
An entity instance A is associated with zero or more instances of entity B, and an entity instance B can be associated with at most one entity instance A
Example In a system that has a Store entity and a Product entity,
a 1:M relationship exists between them A single store can have multiple products, but a
product can belong to at most one store A many-to-one relationship (M:1) exists as well to
indicate the inverse of a 1:M relationship Are there any 1:M relationships in our candy
database?
Sample Database (CANDY)CUST_ID CUST_NAME CUST_TYPE CUST_ADDR CUST_ZIP CUST_PHONE USERNAME PASSWORD
1 Jones, Joe P 1234 Main St. 91212 434-1231 jonesj 12342 Armstrong,Inc. R 231 Globe Blvd. 91212 434-7664 armstrong 33333 Sw edish Burgers R 1889 20th N.E. 91213 434-9090 sw edburg 23534 Pickled Pickles R 194 CityView 91289 324-8909 pickpick 53335 The Candy Kid W 2121 Main St. 91212 563-4545 kidcandy 23516 Waterman, Al P 23 Yankee Blvd. 91234 w ateral 89007 Bobby Bon Bons R 12 Nichi Cres. 91212 434-9045 bobbybon 30118 Crow sh, Elias P 7 77th Ave. 91211 434-0007 crow el 10339 Montag, Susie P 981 Montview 91213 456-2091 montags 9633
10 Columberg Sw eets W 239 East Falls 91209 874-9092 columsw e 8399
PURCH_ID PROD_ID CUST_ID PURCH_DATE DELIVERY_DATE POUNDS STATUS
1 1 5 28-Oct-04 28-Oct-04 3.5 PAID2 2 6 28-Oct-04 30-Oct-04 15 PAID3 1 9 28-Oct-04 28-Oct-04 2 PAID3 3 9 28-Oct-04 28-Oct-04 3.7 PAID4 3 2 28-Oct-04 3.7 PAID5 1 7 29-Oct-04 29-Oct-04 3.7 NOT PAID5 2 7 29-Oct-04 29-Oct-04 1.2 NOT PAID5 3 7 29-Oct-04 29-Oct-04 4.4 NOT PAID6 2 7 29-Oct-04 3 PAID7 2 10 29-Oct-04 14 NOT PAID7 5 10 29-Oct-04 4.8 NOT PAID8 1 4 29-Oct-04 29-Oct-04 1 PAID8 5 4 29-Oct-04 7.6 PAID9 5 4 29-Oct-04 29-Oct-04 3.5 NOT PAID
PROD_ID PROD_DESC PROD_COSTPROD_PRICE
1 Celestial Cashew Crunch 7.45$ 10.00$
2 Unbrittle Peanut Paradise 5.75$ 9.00$
3 Mystery Melange 7.75$ 10.50$
4 Millionaire’s Macadamia Mix 12.50$ 16.00$
5 Nuts Not Nachos 6.25$ 9.50$
CUST_TYPE_IDCUST_TYPE_DESC
P Private
R Retail
W Wholesale
CANDY_CUSTOMER
CANDY_PURCHASE
CANDY_CUST_TYPE
CANDY_PRODUCT
Relationships
Cardinality types Many-to-many (M:M)
An entity instance A is associated with zero or more instances of entity B, and an entity instance B is associated with zero or more instances of entity A
Example In a system that has a Student entity and a Course
entity, a M:M relationship exists between them A student may take zero or more courses, and a
course may have zero or more enrolled students
Are there any M:M relationships in our candy database?
Sample Database (CANDY)CUST_ID CUST_NAME CUST_TYPE CUST_ADDR CUST_ZIP CUST_PHONE USERNAME PASSWORD
1 Jones, Joe P 1234 Main St. 91212 434-1231 jonesj 12342 Armstrong,Inc. R 231 Globe Blvd. 91212 434-7664 armstrong 33333 Sw edish Burgers R 1889 20th N.E. 91213 434-9090 sw edburg 23534 Pickled Pickles R 194 CityView 91289 324-8909 pickpick 53335 The Candy Kid W 2121 Main St. 91212 563-4545 kidcandy 23516 Waterman, Al P 23 Yankee Blvd. 91234 w ateral 89007 Bobby Bon Bons R 12 Nichi Cres. 91212 434-9045 bobbybon 30118 Crow sh, Elias P 7 77th Ave. 91211 434-0007 crow el 10339 Montag, Susie P 981 Montview 91213 456-2091 montags 9633
10 Columberg Sw eets W 239 East Falls 91209 874-9092 columsw e 8399
PURCH_ID PROD_ID CUST_ID PURCH_DATE DELIVERY_DATE POUNDS STATUS
1 1 5 28-Oct-04 28-Oct-04 3.5 PAID2 2 6 28-Oct-04 30-Oct-04 15 PAID3 1 9 28-Oct-04 28-Oct-04 2 PAID3 3 9 28-Oct-04 28-Oct-04 3.7 PAID4 3 2 28-Oct-04 3.7 PAID5 1 7 29-Oct-04 29-Oct-04 3.7 NOT PAID5 2 7 29-Oct-04 29-Oct-04 1.2 NOT PAID5 3 7 29-Oct-04 29-Oct-04 4.4 NOT PAID6 2 7 29-Oct-04 3 PAID7 2 10 29-Oct-04 14 NOT PAID7 5 10 29-Oct-04 4.8 NOT PAID8 1 4 29-Oct-04 29-Oct-04 1 PAID8 5 4 29-Oct-04 7.6 PAID9 5 4 29-Oct-04 29-Oct-04 3.5 NOT PAID
PROD_ID PROD_DESC PROD_COSTPROD_PRICE
1 Celestial Cashew Crunch 7.45$ 10.00$
2 Unbrittle Peanut Paradise 5.75$ 9.00$
3 Mystery Melange 7.75$ 10.50$
4 Millionaire’s Macadamia Mix 12.50$ 16.00$
5 Nuts Not Nachos 6.25$ 9.50$
CUST_TYPE_IDCUST_TYPE_DESC
P Private
R Retail
W Wholesale
CANDY_CUSTOMER
CANDY_PURCHASE
CANDY_CUST_TYPE
CANDY_PRODUCT
Entity-Relationship Models
In a database for an Italian restaurant, match the following items with their component types:
“Entrée” “Pasta Primavera” “Entrée price”
A. EntityB. AttributeC. Entity instanceD. Attribute instance