Chapter 3 : Relational Model

Slides:



Advertisements
Similar presentations
Chapter IV Relational Data Model Pemrograman Sistem Basis Data.
Advertisements

The Relational Model Much of the material presented in these slides was developed by Dr. Ramon Lawrence at the University of Iowa.
CSC271 Database Systems Lecture # 5. Summary: Previous Lecture  Database languages  Functions of a DBMS  DBMS environment  Data models and their categories.
Chapter 3 The Relational Model Transparencies © Pearson Education Limited 1995, 2005.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Chapter 3. 2 Chapter 3 - Objectives Terminology of relational model. Terminology of relational model. How tables are used to represent data. How tables.
Chapter 3: Relational Model
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.
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.
Chapter 4 The Relational Model.
Chapter 3 The Relational Model Transparencies Last Updated: Pebruari 2011 By M. Arief
THE RELATIONAL DATA MODEL CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
CS 3630 Database Design and Implementation. 2 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
Page 1 Topic 4 Relational Databases CPS510 Database Systems Abdolreza Abhari School of Computer Science Ryerson University.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Module 3: The Relational Model.  Overview Terminology Relational Data Structure Mathematical Relations Database Relations Relational Keys Relational.
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 Management System Lecture 4 The Relational Database Model- Introduction, Relational Database Concepts.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Chapter 2 Adapted from Silberschatz, et al. CHECK SLIDE 16.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model.
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.
1 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An = {(x1, x2, x3, …, xn): xi  Ai} R  A1  A2.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
The Relational Model Pertemuan 03 Matakuliah: M0564 /Pengantar Sistem Basis Data Tahun : 2008.
Relational Database. Database Management System (DBMS)
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 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)
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Introduction.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
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,
N-ary Relations & Their Applications. 2 n-ary Relations Let A 1, A 2, …, A n be sets. An n-ary relation on these sets is a subset of A 1 x A 2 x … x A.
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
CS 3630 Database Design and Implementation. 2 Mathematical Relation A mathematical relation is a subset of a Cartesian Product. A1  A2  A3  …  An.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
Chapter 4 The Relational Model Pearson Education © 2009.
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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Relational Model Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3.
Introduction to Relational Model
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
Data Base System Lecture 6: Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
The Relational Model Transparencies
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 4 The Relational Model Pearson Education © 2009.
Chapter 2: Intro to Relational Model
Design tools and techniques for a relational database system
Chapter 2: Intro to Relational Model
Chapter 4 The Relational Model Pearson Education © 2009.
Relational Model B.Ramamurthy 5/28/2019 B.Ramamurthy.
Syllabus Study Introduction to database Relational algebra
Presentation transcript:

Chapter 3 : Relational Model Structure of Relational Databases Fundamental Relational-Algebra Operations Additional Relational-Algebra Operations Extended Relational-Algebra Operations Null Values Modification of Database

Terminologies related To Relational Model Relation – Defined as a table with collection of rows and columns. Data can be stored in the form of a 2D table. Rows will be records and columns will be attributes Attribute – Defined as a named column of a relation. The entities are relations and their attributes are columns of the relation Domain – Defined as a set of allowed values for one or more attributes Tuple – It is a row of a relation. Tuple can appear in any order and the relation will still remain the same relation Extension (state) of a relation – Defined as the set of tuples that appear in that relation at any given instant of time. Extension is same as view of the table

Terminologies related To Relational Model Intension of a relation – A permanent part of the relation, independent of time. Degree of a relation – Defined as the number of attributes it contains. It is property of the intension of a relation Cardinality of a relation – Defined as the number of tuples it contains. It is the property of the extension of the relation Relational database – Defined as the collection of normalized / structured relations with distinct relation names N-ary relation – A relation with degree N

Structure of Relational Databases A relational database consist of collection of Tables, each is assigned a unique name A row in a table represents a relationship among a set of values

Basic Structure Let us consider the “account” table. It has three column headers, account_number, branch_number, balance These headers are attributes For each, there is a set of permitted values, called the DOMAIN of that attribute. For attribute branch_name the domain is the set of all branch names. At physical level the domain of branch name is string of characters Let, D1 - set of all account no.s D2 – set of all branch_names D3 - set of all balances

Basic Structure Any row of “Account” table must consist of a 3-tuples(v1, v2, v3) v1 – account no. (v1 is in D1) v2 – branch name (v2 is in D2) v3 – balance (v3 is in D3) i.e. “Account” is a subset of D1 x D2x D3 A Relation is a subset of Cartesian product of list of domains

Basic Structure A TUPLE variable is a variable whose domain is the set of all tuples i.e. tuple variable t[account_number] denotes the value of t on account number attribute t[account_number] = “A-101” or t[1] = “A-101” t is in relation r For all relations r, the domains of all attributes of r must be atomic. A domain is Atomic if elements of the domain are individual units Null attributes should be eliminated if at all possible

Database Schema We must differentiate between Database Schema Database instance A relation corresponds to the programming language notation of a variable A relational schema corresponds to the programming language notation type definition A relation instance corresponds to the programming language notation of a value of a variable e.g. Account_schema(account_number, branch_name, balance) “Account” is a relation on Account_schema account(Account_schema) i.e. r(R)

Relational Model Notation A relation schema R of degree n is denoted by R(A1, A2, …, An) An n-tuple t in a relation r(R) is denoted by t =<v1, v2, …, vn> where vi is the value corresponding to attribute Ai For component value of a tuple T[Ai], t.Ai and t[i] refers to the value vi in t for attribute Ai T[Au, Aw, …, Az] and t.(Au, Aw, …, Az) where Au, Aw, …, Az is a list of attributes from R, refers to the subtuple of values <vu, vw, …, vz) from t corresponding to the attributes specified in the list The letter Q, R, S denote relation names The letter q, r, s denote relation states The letter t, u, v denote tuples Name of relation indicates the current set of tuples in that relation whereas STUDENT(name, rollno,…) refers relation schema only

Relational algebra Relational algebra and relational calculus are formal languages associated with the relational model Both operands and results are relations, so output from one operation can become input to another operation Allows expressions to be nested, just as in arithmetic. This property is called closure.

Relational Algebra Five basic operations in relational algebra are Selection, Projection, Cartesian product, Union, and Set Difference These perform most of the data retrieval operations needed Also have Join, Intersection, and Division operations, which can be expressed in terms of 5 basic operations

Selection (or Restriction)

Assignment Operation Used to write relational-algebra expression in parts using assignment to a temporary relation variable Denoted by Similar to assignment in programming language

Modification of the Database How to add, remove, or change information in the database We express database modification using the assignment operation

Modification of the DB - Deletion Deletion in relational-algebra is much same as a query Instead of displaying tuples to the user, selected tuples are removed from the database We can delete only whole tuples; we cannot delete values on only particular attributes Deletion is expressed by r r – E Where, r – relation E – relational-algebra query

Modification of the DB - Insertion To insert data into a relation, we specify a tuple to be inserted or write a query whose result is a set of tuples to be inserted The attribute values for inserted tuples must be members of the attribute’s domain Tuples inserted must be of correct arity Insertion is expressed by r r U E Where, r – relation E – relational-algebra expression

Modification of the DB - Updation In some situations we wish to change a value in a tuple without changing all values in the tuple Uses generalized projection for updation Insertion is expressed by r П F1, F2, . . ., Fn(r) Where, Fi – ith attribute of r, if the ith attribute is not updated , or if the attribute is to be updated Fi is an expression, involving only constants and the attributes of r, which gives new value to r To update selected tuples from r r П F1, F2, . . ., Fn(бp (r)) U (r - бp (r))

Extended Relational-algebra operations Generalized projection Outer join Left Right Full Aggregation Functions

Generalized Projection It extends the projection operation by allowing arithmetic functions to be used in the projection list Denoted by П F1, F2, . . ., Fn(E) Where, E – relational-algebra expression F1, F2, . . ., Fn – arithmetic expressions involving constants and attributes in the schema of E

Rename Operation Used to give a name (alias) to relational-algebra expressions or relation Denoted by Greek letter rho X (E) E – relational algebra expression X name given to relational-algebra query expression How to Read it Result of relational-algebra query expression E under the name X

Rename Operation Assume relational algebra expression E has n-arity then X(A1, A2, . . . , An)(E) How to Read it Result of relational-algebra query expression E under the name X, and with the attributes renamed to A1, A2, . . . , An

Aggregate Functions It take collection of values and return a single value as a result List of aggregate functions Sum – returns the sum of values Avg – returns the average of values Count – returns no. of elements in the collection Min – returns the minimum value in the collection Max - returns the maximum value in the collection Note - To eliminate duplicates, same function names with the addition of the hyphenated string distinct

Aggregate Functions count-distinct departmentno (employee) To find out the total sum of salaries of all employees sum salary (employee) Find the number of departments in the employee relation count-distinct departmentno (employee)

Aggregate Functions on Groups In some circumstances we would like to apply aggregate function not only to the single set of tuples but to several groups, where each group is set of tuples Can be done by using an operation called Grouping Denoted by aggregation operator Ç G1, G2, . . ., Gn ÇF1 A1, F2 A2, . . ., Fm Am ( E ) Where, E – relational-algebra expression G1, G2, …, Gn – list of attributes on which to group Fi – an aggregate function Ai – an attribute name

Aggregate Functions on Groups The tuples in result of expression E are partitioned into groups such that All tuples in a group have same values for G1, G2, . . . , Gn All tuples in different groups have different values for G1, G2, . . . , Gn For each group (g1, g2, . . ., gn) the result has a tuple (g1, g2, . . ., gn, a1, a2, . . ., an) Where for each i, ai is the result of applying aggregate function Fi on the multiset of values for attribute Ai in the group

View Definition A view is defined using the create view statement. To define a view, we must give the view name, and must state the query that computes the view. The create view statement is CREATE VIEW v as <query-expression> Where query-expression is any relational-algebra query expression

View Definition A clerk who needs to see all loan data in the loan relation except loan-amount CREATE VIEW branch-loan as Пbranch_name, loan_number(loan) Insertion using view in loan relation branch-loan branch-loan U {(“new panvel”, “L-37”)}

Views Defined Using Other Views CREATE VIEW branch-loanno as Пloan_number(branch-loan)

Types of Keys