1 Database Systems Lecture #3 Yan Pan School of Software, SYSU 2011.

Slides:



Advertisements
Similar presentations
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Advertisements

Information Systems Chapter 4 Relational Databases Modelling.
1 Relational Model and Translating ER into Relational.
1 Lecture 04 Entity/Relationship Modelling. 2 Outline E/R model (Chapter 5) From E/R diagrams to relational schemas (Chapter 5) Constraints in SQL (Chapter.
Lecture #2 October 5 th, 2000 Conceptual Modeling Administration: –HW1 available –Details on projects –Exam date –XML comment.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #2 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #3 Matthew P. Johnson Stern School of Business, NYU Spring, 2005.
Information Resources Management February 13, 2001.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #2 Matthew P. Johnson Stern School of Business, NYU Spring, 2005.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #2 M.P. Johnson Stern School of Business, NYU Spring, 2008.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #3 M.P. Johnson Stern School of Business, NYU Spring, 2008.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #3 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
The Entity-Relationship Data Model
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #5 Matthew P. Johnson Stern School of Business, NYU Spring, 2005.
1 Lecture 3: Database Modeling (continued) April 5, 2002.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #4 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
1 The Entity-Relationship Data Model Chapter 2 (Database Design)
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #4 Matthew P. Johnson Stern School of Business, NYU Spring, 2005.
Lecture 9: Conceptual Database Design January 27 th, 2003.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.
CS411 Database Systems Kazuhiro Minami
Database Design April 3, Projects, More Details Goal: build a DB application. (almost) anything goes. Groups of 3-4. End of week 2: groups formed.
Chapter 4 The Relational Model.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
E/R Diagrams and Functional Dependencies. Modeling Subclasses The world is inherently hierarchical. Some entities are special cases of others We need.
Lecture 08: E/R Diagrams and Functional Dependencies.
Lecture 2: E/R Diagrams and the Relational Model Thursday, January 4, 2001.
Database Management COP4540, SCS, FIU Relational Model Chapter 7.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
Conversion E/R to Relational CIS 4301 Lecture Notes Lecture 6 - 1/31/2006.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Matthew P. Johnson, OCL2, CISDD CUNY, January OCL2 Oracle 10g: SQL & PL/SQL Session #2 Matthew P. Johnson CISDD, CUNY January, 2005.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the.
1 Introduction to Database Systems CSE 444 Lecture 07 E/R Diagrams October 10, 2007.
Tallahassee, Florida, 2015 COP4710 Database Systems E-R Model Fall 2015.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Lecture 2: E/R Diagrams and the Relational Model Wednesday, April 3 rd, 2002.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 2 Introduction to a First Course in Database Systems.
Home Work. Design Principles and Weak Entity Sets.
1 Database Systems Lecture #4 Yan Pan School of Software, SYSU 2011.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
CPSC 603 Database Systems Lecturer: Laurie Webster II, M.S.S.E., M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 4 Introduction to a First Course in Database Systems.
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
The relational model1 The relational model Mathematical basis for relational databases.
Matthew P. Johnson, OCL3, CISDD CUNY, June OCL3 Oracle 10g: SQL & PL/SQL Session #2 Matthew P. Johnson CISDD, CUNY June, 2005.
CS422 Principles of Database Systems Convert ER Design to Relations Chengyu Sun California State University, Los Angeles.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Modeling: Entity-Relationship Diagrams
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Lecture 5: Conceptual Database Design
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
BBM 471 – Database Management Systems
Conceptual Database Design
Translation of ER-diagram into Relational Schema
Lecture 2: Database Modeling (end) The Relational Data Model
Lecture 06 Data Modeling: E/R Diagrams
Chengyu Sun California State University, Los Angeles
Lecture 5: The Relational Data Model
Lecture 08: E/R Diagrams and Functional Dependencies
Presentation transcript:

1 Database Systems Lecture #3 Yan Pan School of Software, SYSU 2011

2 Agenda This time:  Constraints  Relational model  Converting E/R to relations Next time: Functional dependencies

3 Quick topic: Weak entity sets Def: some or all key attributes belong to another ES Plays role in a connecting relationship The key consists of:  Possibly its own attributes and  All key attributes of entity sets from supporting relationships

4 Conditions for supporting relationships Supporting relationship R:E  F  R is many-one (or 1-1) E  F  With referential integrity (rounded arrow)  R is binary  E receives key attributes of F F itself may be weak  Another entity set G, and so on recursively…  A1 A2 R E F

5 For several supporting relships from E to F  Keys of each F role appear as foreign key of E Other, non-supporting many-one relationships are not affected Conditions for weak entity sets Bride Groom Wedding A1 A2 People Witness  

6 Weak entity set e.g. Example: Hierarchy – species & genus Idea: species name unique per genus only Exercise: addresses & logins  address = host  mail.sysu.edu.cn  Password table stores just username Draw E/R diagram with weak entity set Username supported by entity set Host Species Belongs-to Genus 

7 Next topic: Constraints ( 约束 ) Review: programmer-defined rules stating what should always be true about consistent databases Restrictions on data (egs?):  Keys  Single value constraints  Referential Integrity ( 参照完整性 )  Domain constraints  General constraints Can’t infer ( 推断 ) constraints from data  may hold “accidentally”  but they are a part of the schema

8 E/R keys Uniquely identify entity in ES Attribute or set of attributes  Two entities cannot agree on all key attributes  These attributes determine all others Every ES should have a key  possibly including all attributes Primary key attributes underlined More than one possible key:  Candidate keys, primary key Practical tip: create art key attribute  E.g. SSN, course-id, employee-id, etc.  SSN shorter than (name,address) address namessn Person

9 Single-valued constraints “at most one” value  Already saw sharp arrows for relationships Attributes have this automatically  could be null or one value  Can think of key atts as (non-null) single-valued TACourse Assists

10 Referential integrity “ Exactly one value”  NOT NULL & foreign keys in SQL Relationships  Non-null value refers to entity that exists  Refer to entity with foreign key  HTML analogy: no broken links  Programming analogy: no dangling pointers  Multiple ways of handling violations… InstructorCourse Taught

11 Referential integrity – E/R e.g. Insertion – must refer to existing entity Suppose need to add:  course: DBMS  instructor: Yan Pan Q: Which order? Q: What if relship were exactly-exactly, say, M(Hs,Ws)?  i.e., referential integrity in both directions? A: Put both inserts in one xact – later StudentsCourses Enrolls Instructor Taught

12 Other kinds of constraints Domain constraints  E.g. date: must be after 1980  Enumerated type: grades A through F, no E  No special E/R notation just write near line General constraints:  A class may have no more than 100 students; a student may not have more than 6 courses: StudentsCourses Enroll <=6<=100

13 Next topic: the Relational Data Model Invented by Ted Codd  Researcher at IBM  We’ll see his name again… Related work at Berkeley Introduced in a paper a paper published in June, 1970

14 DB development path the World E/R design Relational schema Relational DB

15 Relations as tables Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi tuples/rows/records/entities Attribute names Product table/relation

16 Relational terminology Relation is composed of tuples Tuple = sequence of attribute values  Attribute has atomic types Relation schema: relation name + attribute names + attribute types Database schema: set of relation schemas

17 Relations as sets Recall: math relation is a subset of the cross-product of the attribute value sets  R subset-of S x T  Product subset-of Name x Price x Cat x Mft One member of Product relation:  (gizmo, $19.99, gadgets, GizmoWorks) in Product  Product(gizmo, $19.99, gadgets, GizmoWorks) Usual updates: add/delete/change a tuple in this set Updates to the schema are rare, painful (why?)

18 From E/R models to relations Recall justification:  design is easier in E/R  but implementation is easier/faster in R Analogy to program compilation:  design is easier in C/Java/whatever  implement. is easier/faster in machine/byte code Strategy: 1. apply semi-mechanical conversion rules 2. improve by combining some relations 3. improve by normalization involves finding functional dependencies

19 E/R conversion rules Relationship  relation  attributes: keys of entity-sets/roles  key: depends on multiplicity Entity set  … relation  attributes: attributes of entity set  key: key of ES NB: mapping of types is not one-one  We’ll see: mapping one tokens is also not one-one Special treatment:  Weak entity sets  Isa relations & subclasses

20 Entity Sets Entity set Students ssn name address Students John Howard Name South Carolina Park Avenue AddressSSN Rel: Students

21 Key: keys of both entities Binary many-to-many relationships C C SE CourseIDssn Relation: Enrolls Enrolls S_addr S_Name Students Course Course -Name CourseID ssn

22 Many-to-one relationships Key: keys of many entitiy MoviesStudiosowns 2003SyliaM Mr. Ripley.M101 YearTitleMovieID Movies OrlandoDisneyS73 NYCMiramaxS35 AddressNameStudioID Studios S35 S73 StudioID CN22222 CN11111 CopyrightNo M202 M101 MovieID Owns CopyrightNo MovieID Title Year StudioID Name Address

23 Many-to-one: a better design Q: What if a movie’s Owns row were missing? 2003SyliaM Mr. Ripley.M101 YearTitleMovieID Movies S35 S73 StudioID CN22222 CN11111 CopyrightNo M202 M101 MovieID Owns CN22222 CN11111 CopyrightNo S35 S73 StudioID Year SyliaM202 Talent Mr. Ripley M101 TitleMovieID Movies’

24 Many-to-many relationships again NB: Won’t work for many-many relationships acts MovieIDTitleYear M101Mr. Ripley1999 M202Sylia2003 M303P.D. Love2002 StarIDNameAddress T400Gwyneth P.Bev.Hills T401P.S. HoffmanHollywood T402Jude LawPalm Springs MovieIDStarID M101T400 M202T400 M101T401 M101T402 M303T401 Movies Stars Acts Movies Stars

25 Many-to-many relationships again MovieIDTitleYearStarID M101Talented Mr. Ripley1999T400 M101Talented Mr. Ripley1999T401 M101Talented Mr. Ripley1999T402 M202Syvlia2003T400 M303Punch Drunk Love2003T401 And here’s why:

26 Multiway relationships & roles Different roles treated as different entity sets Key: keys of the many entities StudentsCourses TAs tutorsgraders enrolls TA_SSN Name SSNCourseID Name

27 Multiway relationships & roles Enrolls(S_SSN, Course_ID, Tutor_SSN, Grader_SSN) SSNName George Dick TA_SSNName Wesley Howard John StudentsTAs CourseIDName SE-304Databases C Software Courses S_SSNCourseIDTutor_SSNGrader_SSN SE SE

28 Converting weak ESs – differences Atts of Crew Rel are:  attributes of Crew  key attributes of supporting ESs CrewUnit-ofStudio StudioName Crew_ID address C2Miramax C1Disney C1Miramax Crew_IDStudioName Crew Supporting relships are omitted (why?)

29 Weak entity sets - relationships CrewStudio StudioName Crew_ID address Insurance IName Address th Av.NYBlueCross th Av.NYAetna AddressIName Insurance Subscribes Unit-of

30 Weak entity sets - relationships Non-supporting relationships for weak ESs are converted  keys include entire weak ES key C21 C22 C21 Crew_ID Aetna BlueCross Aetna Insurer Universal Disney Universal StudioName Subscribes

31 Conversion example Video store rental example, plus some atts Q: Conversion to relations? Rental VideoStore Customer Movie date year MName address Cname MID

32 Next week For next week:  Review/skim Ch.3 section 5 (from today)  Read Ch.19 sections 1-3