1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

Chapter 3 : Relational Model
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Information Systems Chapter 4 Relational Databases Modelling.
Lecture 6: Design Constraints and Functional Dependencies January 21st, 2004.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Functional Dependencies Definition: If two tuples agree on the attributes A, A, … A 12n then they must also agree on the attributes B, B, … B 12m Formally:
1 Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design April 16 & 18, 2008.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
1 Lecture 06 The Relational Data Model. 2 Outline Relational Data Model Functional Dependencies FDs in ER Logical Schema Design Reading Chapter 8.
1 Lecture 3: Database Modeling (continued) April 5, 2002.
Lecture 9: Conceptual Database Design January 27 th, 2003.
Multiplicity in E/R Diagrams
Functional Dependencies and Relational Schema Design.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
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.
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.
THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
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.
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.
Lecture 2: E/R Diagrams and the Relational Model Wednesday, April 3 rd, 2002.
Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
1 Web Database The Relational Data Model Irvanizam Zamanhuri, M.Sc Computer Science Study Program Syiah Kuala University Website :
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
CS 157B Database Systems Dr. T Y Lin. Updates 1.Red color denotes updated data (ppt) 2.Class participation will be part of “extra” credits to to “quiz.
Lecture 3: Conceptual Database Design and Schema Design April 12 th, 2004.
1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
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
COP4710 Database Systems E-R Model.
BBM 471 – Database Management Systems
COP4710 Database Systems Relational Model.
Conceptual Database Design
Translation of ER-diagram into Relational Schema
Cse 344 May 14th – Entities.
From E/R Diagrams to Relational Schema
Lecture 4: Database Modeling (continued)
Lecture 2: Database Modeling (end) The Relational Data Model
Lecture 06 Data Modeling: E/R Diagrams
Functional Dependencies and Relational Schema Design
name category name price makes Company Product stockprice buys employs
Introduction to Database Systems CSE 444 Lecture 02: SQL
Functional Dependencies
Lecture 10: The E/R Model III
Lecture 5: The Relational Data Model
Lecture 06: SQL Monday, October 11, 2004.
CS4433 Database Systems E-R Model.
Terminology Product Attribute names Name Price Category Manufacturer
Lectures 2: Introduction to SQL 1
Lecture 08: E/R Diagrams and Functional Dependencies
Lecture 6: Functional Dependencies
Presentation transcript:

1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002

2 Constraints A constraint = an assertion about the database that must be true at all times part of the db schema types in programming languages do not have anything similar correspond to invariants in programming languages

3 Referential Integrity Constraints In some formalisms we may refer to other object but get garbage instead –e.g. a dangling pointer in C/C++ the Referential Integrity Constraint explicitly requires a reference to exist.

4 Referential Integrity Constraints In ODL: – means that a relationship cannot be NULL In E/R: CompanyProduct makes CompanyProduct makes

5 Weak Entity Sets Entity sets are weak when their key attributes come from other classes to which they are related. This happens if: - part-of hierarchies - splitting n-ary relations to binary. UniversityTeam affiliation numbersportname

6 Outline The relational model (3.1) E/R to relational model (3.2) Subclasses to relational model (3.3) ODL to relational model (read on your own, section 4.4).

7 The Relational Data Model Database Model (ODL, E/R) Database Model (ODL, E/R) Relational Schema Relational Schema Physical storage Physical storage ODL definitions Diagrams (E/R) Tables: column names: attributes rows: tuples Complex file organization and index structures.

8 Terminology Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi tuples Attribute names Table name Products:

9 Domains each attribute has a type must be atomic type (why ? see later) called domain examples: –Integer –String –Real –…

10 Schemas Relational Schema: –Relation name plus attribute names –E.g. Product(Name, Price, Category, Manufacturer) –In practice we add the domain for each attribute Database Schema –Set of relational schemas –E.g. Product(Name, Price, Category, Manufacturer), Vendor(Name, Address, Phone),

11 Instances Relational schema = R(A1,…,Ak): Instance = relation with k attributes (of “type” R) –values of corresponding domains Database schema = R1(…), R2(…), …, Rn(…) Instance = n relations, of types R1, R2,..., Rn

12 Example Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi Relational schema:Product(Name, Price, Category, Manufacturer) Instance:

13 Updates The database maintains a current database state. Updates to the data: 1) add a tuple 2) delete a tuple 3) modify an attribute in a tuple Updates to the data happen very frequently. Updates to the schema: relatively rare. Rather painful. Why?

14 Schemas and Instances Analogy with programming languages: –Schema = type –Instance = value Important distinction: –Database Schema = stable over long periods of time –Database Instance = changes constantly, as data is inserted/updated/deleted

15 Two Mathematical Definitions of Relations Relation as cartesian product Tuple = element of string x int x string x string E.g. t = (gizmo, 19, gadgets, GizmoWorks) Relation = subset of string x int x string x string Order in the tuple is important ! –(gizmo, 19, gadgets, GizmoWorks) –(gizmo, 19, GizmoWorks, gadgets) No attributes

16 Relation as a set of functions Fix the set of attributes –A={name, price, category, manufacturer} A tuple = function t:A Domains Relation = set of tuples E.g. Order in a tuple is not important Attribute names are important {name gizmo, price 19, category gadgets, manufacturer gizmoWorks} {name gizmo, price 19, category gadgets, manufacturer gizmoWorks}

17 Two Definitions of Relations We will switch back and forth between these two: –Positional tuples, without attribute names –Relational schemas with attribute names

18 From E/R Diagrams to Relational Schema Easier than ODL (using a liberal interpretation of the word “easy”) - relationships are already independent entities - only atomic types exist in the E/R model. Entity sets relations Relationships relations Special care for weak entity sets.

19 address namessn Person buys makes employs Company Product namecategory Stock price name price

20 Entity Sets to Relations Product namecategory price Product: Name Category Price gizmo gadgets $19.99

21 Relationships to Relations makes Company Product namecategory Stock price name Relation Makes (watch out for attribute name conflicts) Product-name Product-Category Company-name Starting-year gizmo gadgets gizmoWorks 1963 Start Year price

22 Many-one Relationships makes Company Product namecategory Stock price name No need for Makes. Just modify Product: name category price StartYear companyName gizmo gadgets gizmoWorks Start Year price

23 Handling Weak Entity Sets UniversityTeam affiliation numbersportname Relation Team: Sport Number Affiliated University mud wrestling 15 Montezuma State U. - need all the attributes that contribute to the key of Team - don’t need a separate relation for Affiliation. (why ?)

24 Modeling Subclass Structure Product Educational Product Software Product Educ-software Product ageGroup topic Platforms required memory Educational-method isa

25 Option #1: the “ODL” Approach 4 tables: each object can only belong to a single table Product(name, price, category, manufacturer) EducationalProduct( name, price, category, manufacturer, ageGroup, topic) SoftwareProduct( name, price, category, manufacturer, platforms, requiredMemory) EducationalSoftwareProduct( name, price, category, manufacturer, ageGroup, topic, platforms, requiredMemory) All names are distinct

26 Option #2: the E/R Approach Product(name, price, category, manufacturer) EducationalProduct( name, ageGroup, topic) SoftwareProduct( name, platforms, requiredMemory) No need for a relation EducationalSoftwareProduct Unless, it has a specialized attribute: EducationalSoftwareProduct(name, educational-method) Same name may appear in several relations

27 Option #3: The Null Value Approach Have one table: Product ( name, price, manufacturer, age-group, topic, platforms, required-memory, educational-method) Some values in the table will be NULL, meaning that the attribute not make sense for the specific product. Too many meanings for NULL

28 Relational Schema Design Person buys Product name pricenamessn Conceptual Model: Relational Model: (plus FD’s) Normalization:

29 Functional Dependencies A form of constraint (hence, part of the schema) Finding them is part of the database design Also used in normalizing the relations

30 Functional Dependencies Definition: If two tuples agree on the attributes A, A, … A 12n then they must also agree on the attributes B, B, … B 12m Formally: A, A, … A 12n B, B, … B 12m Main (and simplest) example: keys

31 Examples EmpID Name, Phone, Position Position Phone but Phone Position EmpIDNamePhonePosition E0045Smith1234Clerk E1847John9876Salesrep E1111Smith9876Salesrep E9999Mary1234lawyer