Chapter 2: Introduction to Relational Model

Slides:



Advertisements
Similar presentations
Ver 1,12/09/2012Kode :CCs 111,sistem basisdataFASILKOM Chapter 2: Relational Model Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan.
Advertisements

Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Chapter 3: Relational Model
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Relational Model. 2 Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations Extended Relational-Algebra-Operations.
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.
Relational Model Session 6 Course Name: Database System Year : 2012.
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.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
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.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: 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.
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,
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
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.
3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational Calculus Domain Relational.
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Module Coordinator Tan Szu Tak School of Information and Communication Technology, Politeknik Brunei Semester
Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional Relational-Algebra-Operations.
CSc340 1b1 The Relational Model Chapter 2 Database Schema Keys Schema Diagrams Relational Query Languages Relational Operations.
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: Relational Model. 2.2Unite International CollegeDatabase Management Systems Chapter 2: Relational Model Structure of Relational Databases Fundamental.
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. 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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Module A: Formal Relational.
Database System Concepts, 5 th Ed. Bin Mu at Tongji University Chapter 2: Relational Model.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Database System Concepts, 6 th Ed. Chapter 6: Formal Relational Query Languages.
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 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.
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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Module 2: Intro to Relational Model
Introduction to Relational Model
Relational Model By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany)
Chapter 2: Relational Model
Chapter 2: Intro to Relational Model
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: Intro to Relational Model
Chapter 2: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 6: Formal Relational Query Languages
Relational Model.
Chapter 2: Intro to Relational Model
Chapter 2: Intro to Relational Model
Chapter 2: Intro to 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
Lecture 2 Relational Database
Presentation transcript:

Chapter 2: Introduction to Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations

Example of the instructor Relation attributes (or columns) tuples (or rows)

Attribute Types A relation is represented as a table. The term attribute (屬性) refers to a column of a table. 屬性一般指稱物件的特性, 或欲處理的資料. 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 (分割後沒有意義) multivalued attribute values are not atomic (see page 1.17) For example: author = {{Smith, Jones}, {Jones, Frick}} composite attribute values are not atomic For example: publisher = {(McGraw-Hill, New York), (Oxford, London)} The special value null is a member of every domain, which signifies that the value is unknown or does not exist. The null value causes complications in the definition of many operations, and will be discussed later.

Relation Schema and Instance A1, A2, …, An are attributes R = (A1, A2, …, An ) is a relation schema 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 D1 = {a, b, c}, D2 = {1, 2}, D1XD2 = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)} 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) 資料的排序方式屬physical level, 非logical level 寫query時不知資料如何排序; Example: instructor relation with unordered tuples

Database A database consists of multiple relations Information about an enterprise is broken up into parts, where each relation storing one part of the information The university database example: instructor (ID, name, dept_name, salary) department (dept_name, building, budget) student (ID, name, dept_name, tot_cred) course (course_id, title, dept_name, credits) prereq (course_id, prereq_id) Bad design: (c.f. page 1.15) univ (instructor_ID, name, dept_name, salary, student_Id, ..) Normalization theory (Chapter 8) deals with how to design “good” relational schemas.

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}, {name}, and {ID,dept_name} are all superkeys of instructor. (see page 2.5) Superkey K is a candidate key if K is minimal Example: {ID} , {name} are both candidate keys for Instructor One of the candidate keys is selected to be the primary key. which one? 通常依一般使用習慣,找最有代表性的. Another example: {系別, 年級,班級,座號}, {學號}, {身分證字號)都是同學的candidate key, 選 {學號}做為primary key. 注意: Key通常做為物件的代表性屬性 屬性值的唯一性會隨表格表示的資料不同而改變., 如下一頁的dept_name SK CK PK

Foreign Keys Foreign key constraint: Value in one relation must appear in another Referencing relation: e.g., instructor Referenced relation: e.g., department Will discuss this again in Chapter 3 and Chapter 4. department instructor

Schema Diagram for University Database

Relational Query Languages Language in which user requests information from the database. Categories of languages Procedural non-procedural, or declarative “Pure” languages: Relational algebra: procedural Tuple (Domain) relational calculus: declarative “Algebra” is based on operators. Example of arithmetic algebra: 1 + 5*3 How to write a query Determine which relations to use Determine which operators to use

Relational Algebra Relational operators select:  project:  Natural join: Cartesian product: x union:  Intersection:  set difference: – The operators take one or two relations as inputs and produce a new relation as a result.

Selection of tuples σ 限制式(r) Relation r Selection Select tuples with A=B and D > 5 σ A=B ^ D > 5 (r)

Selection of Columns (Attributes) Relation r: Projection  屬性名稱 (r) Select columns A and C  A, C (r) -> duplicates are removed

More Examples Return those instructors whose salaries are more than 85000. (see page 2.5, page2.6) σ salary>=85000 (instructor) Output the attributes ID and Salary of instructors. Π ID, salary (instructor) Find the ID and salary for those instructors who have salary greater than $85000. Π ID, salary (σ salary>=85000 (instructor)) <- composition

Joining two relations – Cartesian Product Relations r, s: r x s: Example: instructor X department => 12*7 = 84 tuples (see page 2.8) <-會希望同一列的dept_name要一樣!

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 Example: R = (A, B, C, D) S = (E, B, D) Result schema = (A, B, C, D, E) r s is defined as: r.A, r.B, r.C, r.D, s.E (r.B = s.B  r.D = s.D (r x s))

Natural Join Example Relations r, s: Natural Join r s

Example Instructor department (c.f., page 2.8) Example: Output the attributes ID and building of instructors.  ID, building (Instructor department)

Union of two relations Relations r, s: r  s: Find the names of instructors and students.  name (instructor)   name (student)

Set difference of two relations Relations r, s: r – s: Find the departments which do not hire instructors.  dept _ name (department) –  dept _ name (instructor)

Set Intersection of two relations Relation r, s: r  s Find the instructors who are also students.  name (instructor)   name (student)