Terminology Product Attribute names Name Price Category Manufacturer

Slides:



Advertisements
Similar presentations
Relational Algebra 1 Chapter 5.1 V3.0 Napier University Dr Gordon Russell.
Advertisements

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:
Lecture #3 Functional Dependencies Normalization Relational Algebra Thursday, October 12, 2000.
One More Normal Form Consider the dependencies: Product Company Company, State Product Is it in BCNF?
Relation Decomposition A, A, … A 12n Given a relation R with attributes Create two relations R1 and R2 with attributes B, B, … B 12m C, C, … C 12l Such.
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:
Integrity Constraints An important functionality of a DBMS is to enable the specification of integrity constraints and to enforce them. Knowledge of integrity.
1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.
Lecture 09: Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
Today Collection of unrelated stuff Questions? HW –4 -5 & drop lowest –emphasize project Projects Functional Dependencies? –Someone asked why: Keys, Normal.
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
1 Lecture 7: Normal Forms, Relational Algebra Monday, 10/15/2001.
1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
CSE 326: Data Structures Lecture #22 Databases and Sorting Alon Halevy Spring Quarter 2001.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Formal definition of a key A key is a set of attributes A 1,..., A n such that for any other attribute B: A 1,..., A n  B A minimal key is a set of attributes.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
Lecture 11: Functional Dependencies
SQL.
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Functional Dependency and Normalization
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
Module 2: Intro to Relational Model
Chapter 2: Relational Model
Relational Algebra at a Glance
CS411 Database Systems 08: Midterm Review Kazuhiro Minami 1.
Schedule Today: Jan. 23 (wed) Week of Jan 28
3.1 Functional Dependencies
Chapter 2: Intro to Relational Model
Problems in Designing Schema
Relational Design Theory
Relational Design Theory
Module 5: Overview of Normalization
Functional Dependencies and Normalization
Principles of Database Management Systems CSE 544
Lecture 2: Database Modeling (end) The Relational Data Model
Relational Design Theory
Lecture 06 Data Modeling: E/R Diagrams
Cse 344 May 16th – Normalization.
Functional Dependencies and Relational Schema Design
Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design October 12 & 15, 2007.
Building a Database Application
Normalization.
Relational Design Theory
Lecture 8: Database Design
Lecture 07: E/R Diagrams and Functional Dependencies
CS 405G: Introduction to Database Systems
Chapter 2: Intro to Relational Model
Instructor: Mohamed Eltabakh
Integrity Constraints
Lecture 5: The Relational Data Model
Chapter 2: Intro to Relational Model
Functional Dependencies
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Relational Database Design
Lectures 2: Introduction to SQL 1
Syllabus Introduction Website Management Systems
Lecture 08: E/R Diagrams and Functional Dependencies
Unit Relational Algebra 1
Lecture 6: Functional Dependencies
Lecture 11: Functional Dependencies
Database.
Chapter 7a: Overview of Database Design -- Normalization
Lecture 09: Functional Dependencies
Presentation transcript:

Terminology Product Attribute names Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $149.99 photography Canon MultiTouch $203.99 household Hitachi tuples (Arity=4) Product(name: string, Price: real, category: enum, Manufacturer: string)

More Terminology Every attribute has an atomic type. Relation Schema: relation name + attribute names + attribute types Relation instance: a set of tuples. Only one copy of any tuple! (not) Database Schema: a set of relation schemas. Database instance: a relation instance for every relation in the schema.

More on Tuples Formally, a mapping from attribute names to (correctly typed) values: name gizmo price $19.99 category gadgets manufacturer GizmoWorks Sometimes we refer to a tuple by itself: (note order of attributes) (gizmo, $19.99, gadgets, GizmoWorks) or Product (gizmo, $19.99, gadgets, GizmoWorks).

Integrity Constraints An important functionality of a DBMS is to enable the specification of integrity constraints and to enforce them. Knowledge of integrity constraints is also useful for query optimization. Examples of constraints: keys, superkeys foreign keys domain constraints, tuple constraints. Functional dependencies, multivalued dependencies.

Keys A minimal set of attributes that uniquely the tuple (I.e., there is no pair of tuples with the same values for the key attributes): Person: social security number name name + address name + address + age Perfect keys are often hard to find, but organizations usually invent something anyway. Superkey: a set of attributes that contains a key. A relation may have multiple keys: (but only one primary key) employee number, social-security number

Foreign Key Constraints Purchase: buyer price product Joe $20 gizmo Jack $20 E-gizmo Product: name manufacturer description gizmo G-sym great stuff E-gizmo G-sym even better An attribute of a relation R is must refer to a key of a relation S.

Functional Dependencies Definition: If two tuples agree on the attributes A , A , … A 1 2 n then they must also agree on the attributes B , B , … B 1 2 m Formally: A , A , … A B , B , … B 1 2 n 1 2 m Key of a relation: all the attributes are either on the left or right.

Some Obvious Properties of FD’s A , A , … A B , B , … B Is equivalent to 1 2 n 1 2 m A , A , … A B 1 2 n 1 Splitting rule and Combing rule A , A , … A B 1 2 n 2 … A , A , … A B 1 2 n m A , A , … A A Always holds. 1 2 n i

Comparing Functional Dependencies Entailment: a set of functional dependencies S1 entails a set S2 if: any database that satisfies S1 much also satisfy S2. Example: A B, B C entails A C Equivalence: two sets of FD’s are equivalent if each entails the other. {A B, B C } is equivalent to {A B, A C, B C} Closure: Given a set of attributes A and a set of dependencies C, we want to find all the other attributes that are functionally determined by A.

Closure Algorithm Start with Closure=A. Until closure doesn’t change do: if is in C, and B is not in Closure then add B to closure. A , A , … A B 1 2 n A , A , … A Are all in the closure, and 1 2 n

Problems in Designing Schema Name SSN Phone Number Fred 123-321-99 (201) 555-1234 Fred 123-321-99 (206) 572-4312 Joe 909-438-44 (908) 464-0028 Joe 909-438-44 (212) 555-4000 Problems: - redundancy - update anomalies - deletion anomalies

Relation Decomposition Break the relation into two relations: Name SSN Fred 123-321-99 Joe 909-438-44 Name Phone Number Fred (201) 555-1234 Fred (206) 572-4312 Joe (908) 464-0028 Joe (212) 555-4000

Boyce-Codd Normal Form A simple condition for removing anomalies from relations: A relation R is in BCNF if and only if: Whenever there is a nontrivial dependency for R , it is the case that { } is a super-key for R. A , A , … A B 1 2 n A , A , … A 1 2 n In English (though a bit vague): Whenever a set of attributes of R is determining another attribute, should determine all the attributes of R.

Relational Algebra Operators: sets as input, new set as output Basic Set Operators union, intersection, difference, but no complement. (watch comparable sets) Selection Projection Division(not in text) Cartesian Product Joins, combination of cart product/selection Unofficially aggregate functions(not in text)

Set Operations Binary operations Sets must be compatible! Result is table(set) with same attributes Sets must be compatible! R1(A1,A2,A3)&R2(B1,B2,B3) Domain(Ai)=Domain(Bi) Union: all tuples in R1 or R2 Intersection: all tuples in R1 and R2 Difference: all tuples in R1 and not in R2 No complement… what’s the universe?

Selection Grab a subset of the tuples in a relation which satisfy a given condition Unary operation… returns set with same attributes, but ‘selects’ rows Use and, or, not, >, <… to build condition Example

Projection Unary operation, selects columns Returned schema is different, so returned tuples are not subset of original set, like they are in selection Eliminates duplicate tuples Example

Cartesian Product Binary Operation Result is tuples combining any element of R1 with any element of R2, for R1XR2 Schema is union of Schema(R1) & Schema(R2) Example Notice we could do selection on result to get meaningful info!

Join Most often used… Combines two relations, selecting only related tuples Equivalent to a cross product followed by selection Resulting schema has all attributes of the two relations, but one copy of join condition attributes Example