INTRODUCTION TO DATA MODELING CS 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 Models
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) Phone numbers: (555) , (555)
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) 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) 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) 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.Entity B.Attribute C.Entity instance D. Attribute instance