Chapter 2: Intro to Relational Model

Slides:



Advertisements
Similar presentations
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Advertisements

Chapter 3 : Relational Model
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Chapter 3: Relational Model
Relational Model & Relational Algebra. 2 Relational Model u Terminology of relational model. u How tables are used to represent data. u Connection between.
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Relational Model Concepts. The relational model represents the database as a collection of relations. Each relation resembles a table of values. A table.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
CIS552Relational Model1 Structure of Relational Database Relational Algebra Extended Relational-Algebra-Operations Modification of the Database.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
CSc340 1b1 The Relational Model Chapter 2 Database Schema Keys Schema Diagrams Relational Query Languages Relational Operations.
The Relational Algebra and Calculus
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Computing & Information Sciences Kansas State University Friday, 26 Jan 2008CIS 560: Database System Concepts Lecture 2 of 42 Friday, 29 August 2008 William.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
Chapter 2: Introduction to Relational Model
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Introduction.
Presented By: Miss N. Nembhard. Relation Algebra Relational Algebra is : the formal description of how a relational database operates the mathematics.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 6 th Edition Chapter 8: Relational Algebra.
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
The Relational Data Model & Relational Algebra
Ritu CHaturvedi Some figures are adapted from T. COnnolly
Midlands State University Topic: Relational DB Model
Module 2: Intro to Relational Model
Chapter # 6 The Relational Algebra and Calculus
Introduction to Relational Model
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Relational Model
Fundamental of Database Systems
Relational Algebra - Part 1
Chapter 2: Intro to Relational Model
Chapter 6: Formal Relational Query Languages
Chapter 3: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Relational Model
Introduction to Database
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Module 5: Overview of Normalization
Chapter 6: Formal Relational Query Languages
Instructor: Mohamed Eltabakh
The Relational Model Transparencies
Relational Model.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Relational Model
Chapter 6: Formal Relational Query Languages
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Chapter 7a: Overview of Database Design -- Normalization
Lecture 2 Relational Database
Presentation transcript:

Chapter 2: Intro to Relational Model

Relation and Terminology A relational database consists of a collection of tables. A row in a table represents a relationship among a set of values. A tuple is a sequence (or list) of values. A relationship between n values is represented by an n-tuple of values. Relation refers to a table, tuple refers to a row. Attribute refers to a column of a table. Relation instance vs. Relation Schema

Example of a Relation attributes (or columns) tuples (or rows)

Attribute Types The set of allowed values for each attribute is called the domain of the attribute Attribute values are (normally) required to be atomic; that is, indivisible E.g., phone number (country code, area code, local number) The special value null is a member of every domain. Indicated that the value is “unknown” The null value causes complications in the definition of many operations When accessing or update the database Should be eliminated if at all possible.

Relation Schema and Instance A1, A2, …, An are attributes R = (A1, A2, …, An ) the set of attributes in the schema of relation r Example: instructor = (ID, name, dept_name, salary) Formally, given sets D1, D2, …. Dn a relation r is a subset of D1 x D2 x … x Dn Thus, a relation is a set of n-tuples (a1, a2, …, an) where each ai  Di The current values (relation instance) of a relation are specified by a table An element t of r is a tuple, represented by a row in a table

Relations are Unordered Order of tuples is irrelevant (tuples may be stored in an arbitrary order) Example: instructor relation with unordered tuples

Keys Let K  R K is a superkey of R if values for K are sufficient to identify a unique tuple of each possible relation r(R) Example: {ID} and {ID,name} are both superkeys of instructor. Superkey K is a candidate key if K is minimal Example: {ID} is a candidate key for Instructor The combination {ID, name}? One of the candidate keys is selected to be the primary key. E.g. Social-security number? Foreign key constraint: Value in one relation must appear in another Referencing relation Referenced relation Example – dept_name in instructor is a foreign key from instructor referencing department

Schema Diagram for University Database

Relational Query Languages Procedural vs .non-procedural, or declarative “Pure” languages: Relational algebra (procedural) Tuple relational calculus (non-procedural) Domain relational calculus (non-procedural) The above 3 pure languages are equivalent in computing power We will concentrate in this chapter on relational algebra Not turning-machine equivalent consists of 6 basic operations

Select Operation – selection of rows (tuples) Relation r A=B ^ D > 5 (r)

Project Operation – selection of columns (Attributes) Relation r: A,C (r)

Union of two relations Relations r, s: r  s:

Set difference of two relations Relations r, s: r – s:

Set intersection of two relations Relation r, s: r  s Note: r  s = r – (r – s)

joining two relations -- Cartesian-product Relations r, s: r x s:

Cartesian-product – naming issue Relations r, s: B r.B s.B r x s:

Renaming a Table Allows us to refer to a relation, (say E) by more than one name.  x (E) returns the expression E under the name X Relations r r.A r.B s.A s.B r x  s (r) α β 1 2 α β 1 2

Composition of Operations Can build expressions using multiple operations Example: A=C (r x s) r x s A=C (r x s)

Joining two relations – Natural Join Let r and s be relations on schemas R and S respectively. Then, the “natural join” of relations R and S is a relation on schema R  S obtained as follows: Consider each pair of tuples tr from r and ts from s. If tr and ts have the same value on each of the attributes in R  S, add a tuple t to the result, where t has the same value as tr on r t has the same value as ts on s

Natural Join Example Relations r, s: Natural Join r s  A, r.B, C, r.D, E ( r.B = s.B ˄ r.D = s.D (r x s)))

Notes about Relational Languages Each Query input is a table (or set of tables) Each query output is a table. All data in the output table appears in one of the input tables Relational Algebra is not Turning complete Can we compute: SUM AVG MAX MIN 21

Summary of Relational Algebra Operators Symbol (Name) Example of Use σ (Selection) σ salary > = 85000 (instructor) Return rows of the input relation that satisfy the predicate. Π (Projection) Π ID, salary (instructor) Output specified attributes from all rows of the input relation. Remove duplicate tuples from the output. x (Cartesian Product) instructor x department Output pairs of rows from the two input relations that have the same value on all attributes that have the same name. ∪ (Union) Π name (instructor) ∪ Π name (student) Output the union of tuples from the two input relations. - (Set Difference) Π name (instructor) -- Π name (student) Output the set difference of tuples from the two input relations. ⋈ (Natural Join) instructor ⋈ department Output pairs of rows from the two input relations that have the same value on all attributes that have the same name.

Exercises Relational database employee (person_name, street, city) works (person_name, company_name, salary) company (company_name, city) 2.7) Give an expression in the relational algebra to express each of the following queries: Find the names of all employees who live in city “Miami” Find the names of all employees whose salary is greater than $100,000 Find the names of all employees who live in “Miami” and whose salary is greater than $100,000

End of Chapter 2