Fall 2001Arthur Keller – CS 1803–1 Schedule Today Oct. 2 (T) Relational Model. u Read Sections 3.1-3.4. Assignment 1 due. Personal Letter of Introduction.

Slides:



Advertisements
Similar presentations
Relational Model Table = relation. Column headers = attributes. Row = tuple Beers Relation schema = name(attributes) + other structure info., e.g., keys,
Advertisements

Database Management Systems Chapter 3 The Relational Data Model (I) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
CSCI 305 – Fall 2013 The Entity-Relationship Model Based on Slides by Prof. Brian King.
Database Management Systems Chapter 3 The Relational Data Model (II) Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
Functional Dependencies - Example
1 Convert E/R to Relation May 18, Entity Set -> Relation Relation: Beers(name, manf) Beers name manf.
Databases : Relational Model 2007, Fall Pusan National University Ki-Joune Li These slides are made from the materials that Prof. Jeffrey D. Ullman distributes.
Chapter 4 Notes. Entity-Relationship Model E/R Diagrams Weak Entity Sets Converting E/R Diagrams to Relations.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
1 Relational Model and Translating ER into Relational.
1 The Relational Data Model Functional Dependencies.
The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes rows: tuples Complex file.
From ER Diagrams to the Relational Model Rose-Hulman Institute of Technology Curt Clifton.
1 Announcement Recitation time  Before midterm: 6-7pm, by Earl Wagner  After midterm: 5-6pm, by Yi Qiao Newsgroup safe to subscribe  Will not cause.
1 Functional Dependencies Meaning of FD’s Keys and Superkeys Inferring FD’s.
Fall 2001Arthur Keller – CS 1802–1 Schedule Today Sep. 25 (T) u More Entity-Relationship Model. u Read Sections Note: Sep. 27 (TH) Class cancelled.
Winter 2002Arthur Keller – CS 1804–1 Schedule Today: Jan. 15 (T) u Normal Forms, Multivalued Dependencies. u Read Sections Assignment 1 due. Jan.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
Fall 2001Arthur Keller – CS 1805–1 Schedule Today Oct. 9 (T) Multivalued Dependencies, Relational Algebra u Read Sections 3.7, Assignment 2 due.
From E/R Diagrams to Relations. The Relational Data Model Database Model (E/R) Relational Schema Physical storage Diagrams (E/R) Tables: row names: attributes.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Source: slides by Jeffrey Ullman.
Winter 2002Arthur Keller – CS 1803–1 Schedule Today: Jan. 10 (TH) u Relational Model, Functional Dependencies. u Read Sections Jan. 15 (T) u Normal.
Winter 2002Arthur Keller – CS 1802–1 Schedule Today: Jan. 8 (T) u Weak Entity Sets, Entity-Relationship Design. u Read Sections Jan. 10 (TH) u.
Fall 2001Arthur Keller – CS 1804–1 Schedule Today Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct.
CS411 Database Systems Kazuhiro Minami
Databases Illuminated
Chapter 4 The Relational Model.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
Normalization Goal = BCNF = Boyce-Codd Normal Form = all FD’s follow from the fact “key  everything.” Formally, R is in BCNF if for every nontrivial FD.
Chapter 3 The Relational Model. 2 Chapter 3 - Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
Entity-Relationship Model
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
Data Modeling Translating E-R Diagrams to Relations
SAnta Clara UniversityHolliday – COEN 1782–1 Today’s Topic Today: u Constraints, Weak Entity Sets, Entity- Relationship Design. u Read Sections
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
CS 405G: Introduction to Database Systems Lecture 5: Logical Design by Relational Model Instructor: Chen Qian.
Databases 1 Fifth lecture. Entity-Relationship Model Diagrams Class hierarchies Weak entity sets From E/R diagrams to Relations 2.
Instructor: Jinze Liu Fall Phases of Database Design u Conceptual design begins with the collection of requirements and results needed from the.
Santa Clara UniversityHolliday – COEN 1783–1 Today’s Topic Today: u Relational Model, Functional Dependencies. u Read Sections Next time u Normal.
1 Multivalued Dependencies Fourth Normal Form Reasoning About FD’s + MVD’s.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Relations, Functions.
Entity-Relationship Model E/R Diagrams Converting E/R Diagrams to Relations.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations Functional Dependencies.
CS 405G: Introduction to Database Systems Relations.
Functional Dependencies Zaki Malik September 25, 2008.
Functional Dependencies. Babies Exercise 2.2.5: At a birth, there is one baby (twins would be represented by two births), one mother, any number of nurses,
Databases 1 Sixth lecture. 2 Functional Dependencies X -> A is an assertion about a relation R that whenever two tuples of R agree on all the attributes.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 The Relational Data Model Tables Schemas Conversion from E/R to Relations.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Introduction to Database Systems, CS420
Entity-Relationship Model
Cushing, Keller, UlmanJudy Cushing
CPSC-310 Database Systems
Instructor: Zhe He Department of Computer Science
CPSC-310 Database Systems
02 - The Relational Database Model
The Relational Data Model
Functional Dependencies
CS 405G Introduction to Database Systems
CS 505: Intermediate Topics to Database Systems
Multivalued Dependencies
CS 405G: Introduction to Database Systems
Presentation transcript:

Fall 2001Arthur Keller – CS 1803–1 Schedule Today Oct. 2 (T) Relational Model. u Read Sections Assignment 1 due. Personal Letter of Introduction and Background due (2% of course grade). Oct. 4 (TH) Functional Dependencies and Normalization. u Read Sections Project Part 1 due. Oct. 9 (T) Multivalued Dependencies, Relational Algebra u Read Sections 3.7, Assignment 2 due.

Fall 2001Arthur Keller – CS 1803–2 Relational Model Table = relation. Column headers = attributes. Row = tuple Beers Relation schema = name(attributes) + other structure info., e.g., keys, other constraints. Example: Beers(name, manf). u Order of attributes is arbitrary, but in practice we need to assume the order given in the relation schema. Relation instance is current set of rows for a relation schema. Database schema = collection of relation schemas.

Fall 2001Arthur Keller – CS 1803–3 A1 A2 A3... An a1 a2 a3 an b1 b2 a3 cn a1 c3 b3 bn. x1 v2 d3 wn Relational Data Model Set theoretic Domain — set of values like a data type Cartesian product (or product) D1  D2 ...  Dn k-tuples (V1,V2,...,Vn) s.t., V1  D1, V2  D2,...,Vn  Dn Relation-subset of cartesian product of one or more domains FINITE only; empty set allowed Tuples = members of a relation inst. Arity = number of domains Components = values in a tuple Domains — corresp. with attributes Cardinality = number of tuples Relation as table Rows = tuples Columns = components Names of columns = attributes Set of attribute names = schema REL (A1,A2,...,An) Arity CardinalityCardinality Attributes Component Tuple

Fall 2001Arthur Keller – CS 1803–4 Name address tel # Cardinality of domain Domains N A T N1 A1 T1 N2 A2 T2 N3 A3 T3 N4 T4 N5 T5 T6 T7 Relation: Example Domain of Relation N A T N1 A1 T1 N1 A1 T2 N1 A1 T3. N1 A1 T7 N1 A2 T1 N1 A3 T1 N2 A1 T1 Arity3 Cardinality<=5x3x7 of relation Tuple µ Domain Component Attribute

Fall 2001Arthur Keller – CS 1803–5 Relation Instance NameAddressTelephone Bob123 Main St Bob128 Main St Pat123 Main St Harry456 Main St Sally456 Main St Sally456 Main St Pat12 State St

Fall 2001Arthur Keller – CS 1803–6 About Relational Model Order of tuples not important Order of attributes not important (in theory) Collection of relation schemas (intension) Relational database schema Corresponding relation instances (extension) Relational database intension vs. extension schema vs. data metadata includes schema

Fall 2001Arthur Keller – CS 1803–7 Keys in Relations An attribute or set of attributes K is a key for a relation R if we expect that in no instance of R will two different tuples agree on all the attributes of K. Indicate a key by underlining the key attributes. Example: If name is a key for Beers : Beers(name, manf)

Fall 2001Arthur Keller – CS 1803–8 Why Relations? Very simple model. Often a good match for the way we think about our data. Abstract model that underlies SQL, the most important language in DBMS’s today. u But SQL uses “bags” while the abstract relational model is set-oriented.

Fall 2001Arthur Keller – CS 1803–9 Relational Design Simplest approach (not always best): convert each E.S. to a relation and each relationship to a relation. Entity Set  Relation E.S. attributes become relational attributes. Becomes: Beers(name, manf)

Fall 2001Arthur Keller – CS 1803–10 E/R Relationships  Relations Relation has attribute for key attributes of each E.S. that participates in the relationship. Add any attributes that belong to the relationship itself. Renaming attributes OK. u Essential if multiple roles for an E.S.

Fall 2001Arthur Keller – CS 1803–11 For one-one relation Married, we can choose either husband or wife as key. Likes(drinker, beer) Favorite(drinker, beer) Married(husband, wife) Buddies(name1, name2)

Fall 2001Arthur Keller – CS 1803–12 Combining Relations Sometimes it makes sense to combine relations. Common case: Relation for an E.S. E plus the relation for some many-one relationship from E to another E.S. Example Combine Drinker(name, addr) with Favorite(drinker, beer) to get Drinker1(name, addr, favBeer). Danger in pushing this idea too far: redundancy. e.g., combining Drinker with Likes causes the drinker's address to be repeated, viz.: Notice the difference: Favorite is many-one; Likes is many-many.

Fall 2001Arthur Keller – CS 1803–13 Weak Entity Sets, Relationships  Relations Relation for a weak E.S. must include its full key (i.e., attributes of related entity sets) as well as its own attributes. A supporting (double-diamond) relationship yields a relation that is actually redundant and should be deleted from the database schema.

Fall 2001Arthur Keller – CS 1803–14 Example Hosts(hostName) Logins(loginName, hostName) At(loginName, hostName, hostName2) In At, hostName and hostName2 must be the same host, so delete one of them. Then, Logins and At become the same relation; delete one of them. In this case, Hosts ’ schema is a subset of Logins ’ schema. Delete Hosts ?

Fall 2001Arthur Keller – CS 1803–15 Subclasses  Relations Three approaches: 1. Object-oriented: each entity is in one class. Create a relation for each class, with all the attributes for that class. u Don’t forget inherited attributes. 2. E/R style: an entity is in a network of classes related by isa. Create one relation for each E.S. u An entity is represented in the relation for each subclass to which it belongs. u Relation has only the attributes attached to that E.S. + key. 3. Use nulls. Create one relation for the root class or root E.S., with all attributes found anywhere in its network of subclasses.  Put NULL in attributes not relevant to a given entity.

Fall 2001Arthur Keller – CS 1803–16 Example

Fall 2001Arthur Keller – CS 1803–17 OO-Style E/R Style BeersAles BeersAles Beers Using NULLS

Fall 2001Arthur Keller – CS 1803–18 Functional Dependencies X  A = assertion about a relation R that whenever two tuples agree on all the attributes of X, then they must also agree on attribute A. Important as a constraint on the data that may appear within a relation. u Schema-level control of data. Mathematical tool for explaining the process of “normalization” – vital for redesigning database schemas when original design has certain flaws.

Fall 2001Arthur Keller – CS 1803–19 Example Drinkers(name, addr, beersLiked, manf, favoriteBeer) Reasonable FD's to assert: 1. name  addr 2. name  favoriteBeer 3. beersLiked  manf Note: These happen to imply the underlined key, but the FD’s give more detail than the mere assertion of a key.

Fall 2001Arthur Keller – CS 1803–20 Key (in general) functionally determines all attributes. In our example: Name beersLiked  addr favoriteBeer beerManf Shorthand: combine FD's with common left side by concatenating their right sides. When FD's are not of the form Key  other attribute(s), then there is typically an attempt to “cram” too much into one relation. Sometimes, several attributes jointly determine another attribute, although neither does by itself. Example: beer bar  price

Fall 2001Arthur Keller – CS 1803–21 Formal Notion of Key K is a key for relation R if: 1. K  all attributes of R. (Uniqueness) 2. For no proper subset of K is (1) true. (Minimality) If K at least satisfies (1), then K is a superkey. FD Conventions X, etc., represent sets of attributes; A etc., represent single attributes. No set formers in FD’s, e.g., ABC instead of {A, B, C}.

Fall 2001Arthur Keller – CS 1803–22 Example Drinkers(name, addr, beersLiked, manf, favoriteBeer) { name, beersLiked } FD’s all attributes, as seen.  Shows { name, beersLiked } is a superkey. name  beersLiked is false, so name not a superkey. beersLiked  name also false, so beersLiked not a superkey. Thus, { name, beersLiked } is a key. No other keys in this example.  Neither name nor beersLiked is on the right of any observed FD, so they must be part of any superkey.

Fall 2001Arthur Keller – CS 1803–23 Example 2 Keys are { Lastname, Firstname } and { StudentID } Lastname Firstname Student ID Major Key (2 attributes) Superkey Note: There are alternate keys

Fall 2001Arthur Keller – CS 1803–24 Who Determines Keys/FD’s? We could define a relation schema by simply giving a single key K.  Then the only FD's asserted are that K  A for every attribute A. No surprise: K is then the only key for those FD’s, according to the formal definition of “key.” Or, we could assert some FD’s and deduce one or more keys by the formal definition. u E/R diagram implies FD’s by key declarations and many-one relationship declarations. Rule of thumb: FD's either come from keyness, many-1 relationship, or from physics.  E.g., “no two courses can meet in the same room at the same time” yields room time  course.