Presentation is loading. Please wait.

Presentation is loading. Please wait.

CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.

Similar presentations


Presentation on theme: "CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution."— Presentation transcript:

1 CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from http://everaldo.com/crystal/.

2 Week 3 The ER Model

3 The Relational Model persona species_type species

4 1. Serves the purpose. 2. Simplifies updates. 3. Avoids “anomalies”. Good DB Design

5 Two Approaches 1. Start with whatever, then fix it 2. Start by modeling ER Modeling

6 The DB Lifecycle requirements analysis implementation deployment design

7 clientyoudatabaseusers the problem functional specification clarification a design a schema use feedback a new problem

8 Functional Specifications What is the system going to do? (Not how, but what.)

9 Course Enrollment What do we want from a course enrollment system?

10 “Use Cases” A student wants to enroll in a course for the next semester. The student goes to the website for the enrollment system and logs in. The student is presented with a list of courses there he or she is enrolled in. There is a button next to each course to un-enroll from it. There is also a search box that the student can use use to look for courses that they are not enrolled in. The student can find the course by the course code or course title...

11 ER Model E is for “Entities” R is for “Relationships” (“relationships” != “relations”)

12 “Use Cases” A student wants to enroll in a course for the next semester. The student goes to the website for the enrollment system and logs in. The student is presented with a list of courses there he or she is enrolled in. There is a button next to each course to un-enroll from it. There is also a search box that the student can use use to look for courses that they are not enrolled in. The student can find the course by the course code or course title...

13 Entities The “things” we need to keep track of in our database: students courses instructors rooms time slots

14 student last name first name utorid date of birth attributes programcoursepayment other entities

15 Entities vs Attributes Attributes usually atomic values, e.g. a number, a string, a date Entities bundles of values (But are dates really atomic?)

16 One Entity or Two? The book and its author? The book and its title? The film and its director? The film and its title? The city and its population? The city and its mayor? The user and their account?

17 student last name first name utorid date of birth “Chen’s notation”

18 student ---------------------------------------------------------------------------------- last name first name utorid date of birth “UML notation” (simplified)

19 Type vs Instance Entity as a type When we say “student” we really mean “students” as a type. Instances of entities Individual students’ records are instances of the “student” entity.

20 program ----------------------------------------------------------------------------------... course ----------------------------------------------------------------------------------... payment ----------------------------------------------------------------------------------... student ---------------------------------------------------------------------------------- last name first name utorid date of birth

21 program ---------------------------------------------------------------------------------- name code course ---------------------------------------------------------------------------------- code title payment ---------------------------------------------------------------------------------- amount date session ---------------------------------------------------------------------------------- code start date student is in a program student made a payment student is enrolled in a course course is offered in a session student ---------------------------------------------------------------------------------- last name first name utorid date of birth course belongs to a program

22 ER vs Data Flow Diagrams ER Diagrams The structure of the data itself Data Flow Diagrams The flow of data between the different processing steps.

23 ProfessorStudent database “persistent storage” submits assignment submits grade the grade is stored the grade is retrieved displays grade 1 2 3 4 4 This is NOT what we are doing represents an actual live student

24 program ---------------------------------------------------------------------------------- name code course ---------------------------------------------------------------------------------- code title payment ---------------------------------------------------------------------------------- amount date session ---------------------------------------------------------------------------------- code start date student is in a program student made a payment student is enrolled in a course course is offered in a session student ---------------------------------------------------------------------------------- last name first name utorid date of birth course belongs to a program represents our record of a student

25 Two Degrees 1.A box in an IR diagram represents a type of record. 2.Records stores information about things in the real world.

26 A Movie Database What are the entities? Which are related?

27

28 Cardinality student ---------------------------------------------------------------------------------- last name first name utorid date of birth payment ---------------------------------------------------------------------------------- amount date payment ---------------------------------------------------------------------------------- amount date payment ---------------------------------------------------------------------------------- amount date payment ---------------------------------------------------------------------------------- amount date payment ---------------------------------------------------------------------------------- amount date one student, many payments “one-to-many” relationship

29 student ---------------------------------------------------------------------------------- last name first name utorid date of birth payment ---------------------------------------------------------------------------------- amount date “Crow’s Foot Notation”

30 not more than 1many “Crow’s Foot Notation”

31

32 at least 1 (mandatory) could be 0 (optional) “Crow’s Foot Notation” 1..10..N

33 just one zero or many “UML Notation” 1..1 or just “1” 0..N or “0..*” 1..10..N

34 at least 1 (mandatory) “Weak Entity” a weak entity studentpayment

35 More Examples worldcharacter speciespet courseassignment ???

36 Variations ownerpet manageremployee ???

37 Questions on 1:M?

38 WeWe ❤ 1:M Because they are really easy to represent in a relational database.

39 Many-to-Many student ---------------------------------------------------------------------------------- last name first name utorid date of birth course ---------------------------------------------------------------------------------- code title

40 Examples bookauthor personaddress courseinstructor ???

41 Movie Database Which relationships are 1:M and which are M:M?

42 We ! ❤ M:M Because they cannot be represented in a relational database.

43 Breaking Up M:M student ---------------------------------------------------------------------------------- last name first name utorid date of birth course ---------------------------------------------------------------------------------- code title

44 “Associative Entity” student ---------------------------------------------------------------------------------- last name first name utorid date of birth course ---------------------------------------------------------------------------------- code title enroll ment

45 Examples book author author ship ??? person address reside nce

46 Questions on M:M?

47 One-to-One ???

48 One-to-One ???

49 One-to-One enginecar the engine is installed in the car engines in stock cars shipped

50 Examples citymayor captainship chef signature dish ???

51 Recursive Relationships person likes

52 Recursive Relationships person likes

53 Examples employee tax return coin image ??? is filed jointly with supervises is the flip side of ???

54 N-nary Relationships seller sold (what?) to the buyer sellerbuyer house seller sold house (to whom?) buyer bought house (from whom?)

55 N-nary Relationships seller buys a house from buyer sellerbuyer house

56 N-nary Relationships seller house buyer sale

57 Putting It Together ● OpenOffice Draw – Free / open source – Available in the lab – You can get “Crow’s Foot” templates at http://www.thinktek.ca/articles/article2.php – Alternatively, do UML notation (“n..m”) by hand ● Microsoft Visio ● Your favorite software Options for software:

58 Questions?

59 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url probably redundan t might be redundan t

60 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url student enrolls in course course is offered in session course meets in room room is in building

61 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url student ---------------------------------------------- -- last name first name

62 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url

63 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrol lmen t

64 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrol lmen t

65 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce

66 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce

67 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce

68 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce

69 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrol lmen t cours e insta nce

70 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?

71 course ---------------------------------------------- -- code title session ---------------------------------------------- -- code start date student ---------------------------------------------- -- last name first name room ---------------------------------------------- -- number capacity building ---------------------------------------------- -- code map url enrollment ---------------------------------------------- -- course instance ---------------------------------------------- -- final exam?

72 Questions?

73


Download ppt "CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution."

Similar presentations


Ads by Google