1 / 25

CS411 Database Systems

Learn about the steps involved in building a database application, from picking an application domain to implementing the code and user interface. Understand the Entity-Relationship model and how to convert it to a data model.

lottiet
Download Presentation

CS411 Database Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS411Database Systems Kazuhiro Minami 02: The Entity-Relationship Model

  2. Steps in building a DB application Pick application domain Conceptual design What data do I need for my application domain? How can I describe that data?

  3. Steps in building a DB application Step 1 Step 2 Pick application domain Conceptual design SQL & Java/C+++/etc + user interface ERdiagram Step 3 Steps 4 and 5 Convert ER diagram to the data model of your DBMS product Implement application code & user interface

  4. Entity Relationship (ER) Model by Peter Chen • Born in Taiwan • Ph.D from Harvard University in 1973 • Professor at Louisiana State University Ted Codd "A Relational Model of Data for Large Shared Data Banks” "The Entity-Relationship Model--Toward a Unified View of Data” 1970 1976

  5. The ER model is very simple name name category price makes Company Product stockprice buys employs Person name ssn address

  6. price name category Company name Product  boardOfDirectors stockprice Entity • real-world object distinguishable from other objects • described by its attributes Attribute • Has an atomic domain: string, integers, date, … Entity set: all have the same set of attributes

  7. Relationships makes Company Product 1 a b 2 A c 3 B d If A, B are sets, then a relation R is a subset of A x B. A = {1, 2, 3} B = {a, b, c, d} R = {(1,a), (1,c), (3,b)} makes is a subset of Product x Company:

  8. We can show the cardinality of a relationship makes Company Product 1 2 3 1 2 3 1 2 3 a b c d a b c d a b c d E F one-one many-one many-many

  9. name category name price makes Company Product stockprice buys employs Person name ssn address

  10. Exercise Design a database for a bank, including information about customers and their accounts. Information about a customer includes their name, address, phone, and Social Security number. Accounts have numbers, types (e.g., saving, checking) and balances. Also record the customer(s) who own an account. Draw the E/R diagram for this database. Change your diagram so an account can have only one customer. Further change your diagram so a customer can have only one account Change your original diagram in (1) so that a customer have a set of addresses.

  11. Phone Address own Customers Accounts SSN Type Balance Name

  12. How do we model a multiway relationship? Product Purchase Store Person Can still model as a mathematical set (how?)

  13. What do arrows mean in n-way relationships? Invoice VideoStore Rental Movie Person If I know the store, person, and invoice, then there is only one possible movie. “VideoStore, Invoice, and Person determines Movie”

  14. What if there are several arrows? Invoice VideoStore Rental Movie Person store, person, invoice determines movie; store, invoice, movie determines person

  15. How do I say “invoice determines store”? Invoice VideoStore Rental Movie Person No good way; best approximation: Why is this incomplete?

  16. What if we need an entity set twice in one relationship? the “role” Product Purchase Store salesperson buyer Person Person

  17. What if we need an entity set twice in one relationship? Product Purchase Store buyer salesperson Person

  18. Some versions of the ER model allow attributes on relationships date Product Purchase Store Person

  19. You can “upgrade” a relationship to be an entity set ProductOf date Product Purchase StoreOf Store BuyerOf Person

  20. Constraint = assertion about the DB that must always be true Key: social security number uniquely identifies a person. Single-value constraint: a person can have only one father. Referential integrity: if a person works for a company, the company must also be in the DB. Domain constraint: peoples’ ages are between 0 and 150. General constraint: all others (at most 100 students in this course)

  21. Constraints are very important • Examples: • Erbana, IL 61801 • Brittany Speers • Help us to come up with efficient storage, query processing, etc. • Help us keep garbage out of the DB • Garbage in, garbage out!

  22. Underline the key for each entity set name category multi-attribute keys are okay! price Product Multiple “candidate keys”? Pick just one to be the key. Person Is this a good key? name ssn address

  23. Referential Integrity Constraints • The reference integrity constraint on relationships explicitly requires a reference to exist • The DB equivalent of a dangling pointer makes Company Product makes Company Product )

  24. Degree Constraints • Constraints on degree of a relationship <= 5 takes Courses Students

  25. Sometimes your entity might not seem to have a key Weak entity set: some or all of its key attributes come from other classes to which it is related. affiliation Team University ) sport record name

More Related