Databases Illuminated

Slides:



Advertisements
Similar presentations
The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
Advertisements

IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Chapter 3 : Relational Model
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
Concepts of Database Management Sixth Edition
The Relational Database Model
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
1 Minggu 2, Pertemuan 3 The Relational Model Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
1 Pertemuan 04 MODEL RELASIONAL Matakuliah: >/ > Tahun: > Versi: >
Database Architecture The Relational Database Model.
3 The Relational Model MIS 304 Winter Class Objectives That the relational database model takes a logical view of data That the relational model’s.
The Relational Database Model
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
Chapter 4 The Relational Model Pearson Education © 2014.
© Pearson Education Limited, Chapter 2 The Relational Model Transparencies.
Relational Model Session 6 Course Name: Database System Year : 2012.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
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.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Relational Algebra References: Databases Illuminated by Catherine Ricardo, published by Jones and Bartlett in 2004 Fundamentals of Relational Databases.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Announcements Reading for Friday –4.7 – 4.10 Homework 3 – Due 10/1 Project: Steps 2.1-2? –Due 10/4 Exam 1 – 10/6.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra)
1.1 CAS CS 460/660 Introduction to Database Systems Relational Algebra.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
Databases Illuminated Chapter 3 The Entity Relationship Model.
Announcements Reading for Monday –4.6 Homework 3 – Due 9/29.
Advanced Relational Algebra & SQL (Part1 )
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
The Relational Model. 2 Relational Model Terminology u A relation is a table with columns and rows. –Only applies to logical structure of the database,
3 1 Database Systems The Relational Database Model.
3 1 Chapter 3 The Relational Database Model Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
CHAPTER 2 : RELATIONAL DATA MODEL Prepared by : nbs.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Mapping ER to Relational Model Each strong entity set becomes a table. Each weak entity set also becomes a table by adding primary key of owner entity.
CSCI 6315 Applied Database Systems Review for Midterm Exam I Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
Chapter 4 The Relational Model Pearson Education © 2009.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
The Relational Data Model & Relational Algebra
Logical Database Design and the Rational Model
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Lecture 2 The Relational Model
The Relational Database Model
Chapter 3 The Relational Database Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
More Relational Algebra
The Relational Model Transparencies
Presentation transcript:

Databases Illuminated Chapter 4 The Relational Model

Advantages of Relational Model Provides data independence-separates logical from physical level Based on mathematical notion of relation Can use power of mathematical abstraction Can develop body of results using theorem and proof method of mathematics–apply to many different applications Can use expressive, exact mathematical notation Theory provides tools for improving design Basic structure is simple, easy to understand Data operations easy to express, using a few powerful commands Operations do not require user to know storage structures used

Data Structures Relations are represented physically as tables Tables are related to one another Table holds information about entities (objects) Rows (tuples) correspond to individual records Columns correspond to attributes A column contains values from one domain Domains consist of atomic values

Properties of Tables Each cell contains at most one value Each column has a distinct name, the name of the attribute it represents Values in a column all come from the same domain Each tuple is distinct – no duplicate tuples Order of tuples is immaterial

Example of Relational Model See Figure 4.1 Student table tells facts about students Faculty table shows facts about faculty Class table shows facts about classes, including what faculty member teaches each Enroll table relates students to classes

Mathematical Relations For two sets D1 and D2, the Cartesian product, D1 X D2 , is the set of all ordered pairs where the first element is from D1 and the second from D2 A relation is any subset of the Cartesian product Could form Cartesian product of 3 sets; relation is any subset of the ordered triples so formed Could extend to n sets, using n-tuples

Database Relations A relation schema, R, is a set of attributes A1, A2,…,An with their domains D1, D2,…Dn A relation r on relation schema R is a set of mappings from the attributes to their domains r is a set of n-tuples (A1:d1, A2:d2, …, An:dn) such that d1ϵ D1, d2 ϵ D2 , …, dn ϵ Dn In a table to represent the relation, list the Ai as column headings, and let the (d1, d2, …dn) become the n-tuples, the rows of the table

Properties of Relations Degree: the number of attributes 2 attributes - binary; 3 attributes - ternary; n attributes - n-ary A property of the intension – does not change unless database design changes Cardinality: the number of tuples Changes as tuples are added or deleted A property of the extension – changes often Keys Integrity constraints

Relation Keys Relations never have duplicate tuples, you can always tell tuples apart; implies there is always a key (which may be a composite of all attributes, in worst case) Superkey: set of attributes that uniquely identifies tuples Candidate key: superkey such that no proper subset of itself is also a superkey (i.e. it has no unnecessary attributes) Primary key: candidate key chosen for unique identification of tuples Cannot verify a key by looking at an instance; need to consider semantic information to ensure uniqueness A foreign key is an attribute or combination of attributes that is the primary key of some relation (called its home relation)

Integrity Constraints Integrity: correctness and internal consistency Integrity constraints-rules or restrictions that apply to all instances of the database Enforcing integrity constraints ensures only legal states of the database are created Types of constraints Domain constraint - limits set of values for attribute Entity integrity: no attribute of a primary key can have a null value Referential integrity: each foreign key value must match the primary key value of some tuple in its home relation or be completely null. General constraints or business rules: may be expressed as table constraints or assertions

Representing Relational Database Schemas Can have any number of relation schemas For each relation schema, list name of relation followed by list of attributes in parentheses Underline primary key in each relation schema Indicate foreign keys (We use italics – arrows are best) Database schema actually includes domains, views, character sets, constraints, stored procedures, authorizations, etc. Example: University database schema Student (stuId, lastName, firstName, major, credits) Class (classNumber, facId, schedule, room) Faculty (facId, name, department, rank) Enroll(stuId,classNumber,grade)

Types of Relational Data Manipulation Languages Procedural: proscriptive - user tells system how to manipulate data - e.g. relational algebra Non-procedural: declarative - user tells what data is needed, not how to get it - e.g. relational calculus, SQL Other types: Graphical: user provides illustration of data needed e.g. Query By Example(QBE) Fourth-generation: 4GL uses user-friendly environment to generate custom applications Natural language: 5GL accepts restricted version of English or other natural language

Relational Algebra Theoretical language with operators that apply to one or two relations to produce another relation Both operands and results are tables Can assign name to resulting table (rename) SELECT, PROJECT, JOIN allow many data retrieval operations

SELECT Operation Applied to a single table, returns rows that meet a specified predicate, copying them to new table Returns a horizontal subset of original table SELECT tableName WHERE condition [GIVING newTableName] Symbolically, [newTableName = ]  predicate (table-name) Predicate is called theta-condition, as in (table-name) Result table is horizontal subset of operand Predicate can have operators <, <=, , =, =, <>, (AND), (OR),  (NOT)

PROJECT Operation Operates on single table Returns unique values in a column or combination of columns PROJECT tableName OVER (colName,...,colName) [GIVING newTableName] Symbolically [newTableName =]  colName,...,colName (tableName) Can compose SELECT and PROJECT, using result of first as argument for second

NATURAL JOIN Operation Requires two tables with common column(s) (at least with same domain) combines the matching rows-rows of the two tables that have the same values in the common column(s) symbolized by |x| as in [newTableName = ] Student |x| Enroll, or Student JOIN Enroll [GIVING newTableName]

Product and Theta-join Binary operations – apply to two tables Product: Cartesian product – cross-product of A and B – A TIMES B, written A x B all combinations of rows of A with rows of B Degree of result is deg of A + deg of B Cardinality of result is (card of A) * (card of B) THETA join: TIMES followed by SELECT A |x| B = (A x B)

Set Operations Tables must be union compatible – have same basic structure A UNION B: set of tuples in either or both of A and B, written A  B A INTERSECTION B: set of tuples in both A and B simultaneously, written A ∩ B Difference or A MINUS B: set of tuples in A but not in B, written A - B

Views External models in 3-level architecture are called external views Relational views are slightly different Relational view is constructed from existing (base) tables can be a window into a base table (subset) can contain data from more than one table can contain calculated data hide portions of database from users External model may have views and base tables

Mapping ER to Relational Schema Each strong entity set becomes a table Non-composite, single-valued attributes become attributes of table Composite attributes: either make the composite a single attribute or use individual attributes for components, ignoring the composite Multi-valued attributes: remove them to a new table along with the primary key of the original table; also keep key in original table Weak entity sets become tables by adding primary key of owner entity Binary Relationships: 1:M-place primary key of 1 side in table of M side as foreign key 1:1- make sure they are not the same entity. If not, use either key as foreign key in the other table M:M-create a relationship table with primary keys of related entities, along with any relationship attributes Ternary or higher degree relationships: construct relationship table of keys, along with any relationship attributes

Equi-join and Natural Join EQUIJOIN formed when  is equality on column common to both tables (or comparable columns) The common column appears twice in the result Eliminating the repeated column in the result gives the NATURAL JOIN, usually called just JOIN A |x| B

Semijoins and Outerjoins Left semijoin A|x B is formed by finding A|x|B and projecting result onto attributes of A Result is tuples of A that participate in the join Right semijoin A x| B defined similarly; tuples of B that participate in join Outerjoin is formed by adding to the join those tuples that have no match, adding null values for the attributes from the other table e.g. A OUTER- EQUIJOIN B consists of the equijoin of A and B, supplemented by the unmatched tuples of A with null values for attributes of B and the unmatched tuples of B with null values for attributes of A Can also form left outerjoin or right outerjoin

Division Binary operator where entire structure of one table (divisor) is a portion of structure of the other (dividend) Result is projection onto those attributes of the dividend that are not in the divisor of the tuples of dividend that appear with all the rows of the divisor It tells which values of those attributes appear with all the values of the divisor