CS634 Information Systems Dr Deepak B Phatak Subrao Nilekani Chair Professor Kanwal Rekhi Building, Department of CSE IIT Bombay Session 3, Relational.

Slides:



Advertisements
Similar presentations
Data Bits Models Classes & Schemes Rows & Tables Keys Associations $100 $200 $300 $400 $500 $100 $200 $300 $400 $500 Final DataBit.
Advertisements

The Relational Model and Relational Algebra Nothing is so practical as a good theory Kurt Lewin, 1945.
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Foundations of Relational Implementation n Defining Relational Data n Relational Data Manipulation n Relational Algebra.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
The Relational Database Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Murali Mani The Relational Model. Murali Mani Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still.
Relational Model and Relational Algebra Rose-Hulman Institute of Technology Curt Clifton.
Database Systems Chapter 5 ITM 354. Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations.
CS405G: Introduction to Database Systems Final Review.
The Relational Model Codd (1970): based on set theory Relational model: represents the database as a collection of relations (a table of values --> file)
Thomas Connolly and Carolyn Begg’s
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
Databases Illuminated
Concepts of Database Management, Fifth Edition
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.
44220: Database Design & Implementation Logical Data Modelling Ian Perry Room: C48 Tel Ext.: 7287
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.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Introduction to Accounting Information Systems
CS609 Introduction. Databases Current state? Future?
Introduction to SQL Steve Perry
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
FEN  Concepts and terminology  Operations (relational algebra)  Integrity constraints The relational model.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
ICOM 5016 – Introduction to Database Systems Lecture 5b Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Chapter 6 The Relational Data Model and the Relational Algebra.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Databases. Not All Tables Are Created Equal Spreadsheets use tables to store data and formulas associated with that data The “meaning” of data is implicit.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
CS 634 Information Systems Dr Deepak B Phatak Subrao Nilekani Chair Professor Kanwal Rekhi Building, Department of CSE IIT Bombay Session 8, Software Engineering,
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
Relational Algebra – Part 2
CS640 Information Systems Dr Deepak B Phatak Subrao Nilekani Chair Professor Kanwal Rekhi Building, Department of CSE IIT Bombay Session 7, SQL DML and.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Concepts 2440: 180 Database Concepts Instructor:
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.
Chapter 2 Introduction to Relational Model. Example of a Relation attributes (or columns) tuples (or rows) Introduction to Relational Model 2.
Advanced Relational Algebra & SQL (Part1 )
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
Database Management Supplement 1. 2 I. The Hierarchy of Data Database File (Entity, Table) Record (info for a specific entity, Row) Field (Attribute,
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 5 – September 4 th,
The Relational Model © Pearson Education Limited 1995, 2005 Bayu Adhi Tama, M.T.I.
The relational model1 The relational model Mathematical basis for relational databases.
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 Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
COMP3017 Advanced Databases
Relational Algebra Chapter 4, Part A
Relational Databases Relational Algebra (1) Select, project, join.
Presentation transcript:

CS634 Information Systems Dr Deepak B Phatak Subrao Nilekani Chair Professor Kanwal Rekhi Building, Department of CSE IIT Bombay Session 3, Relational Model

Dr. Deepak B Phatak2 IIT BOMBAY CS634-Session 3 Relational Model Session overview Review of earlier sessions Introduction to relational model Group projects

Dr. Deepak B Phatak3 IIT BOMBAY CS634-Session 3 Relational Model sroll Entity model Student sname shostel sroom scpi scourses shobbies

Dr. Deepak B Phatak4 IIT BOMBAY CS634-Session 3 Relational Model Table representation srollsnameshostel Ajay Shah Nandan Nilekani 08 … … …

Dr. Deepak B Phatak5 IIT BOMBAY CS634-Session 3 Relational Model ccode Course entity Course cname cstudents cfaculty ccredits

Dr. Deepak B Phatak6 IIT BOMBAY CS634-Session 3 Relational Model TABLE REPRESENTATION ccodecnameccredit CS634Modern Info Systems 06 CS101Computer Programming08 … … …

Dr. Deepak B Phatak7 IIT BOMBAY CS634-Session 3 Relational Model Student and course association Student Set Course Set CS634 CS101 ME203 EE102

Dr. Deepak B Phatak8 IIT BOMBAY CS634-Session 3 Relational Model Relationship set Student Registers For Course sroll ccode

Dr. Deepak B Phatak9 IIT BOMBAY CS634-Session 3 Relational Model Relationship set attribute(s) Student Registers For Course sroll ccode Grade

Dr. Deepak B Phatak10 IIT BOMBAY CS634-Session 3 Relational Model Introduction to relational model Developed by professor Codd Part of system-R work at IBM Mathematical foundation for database modeling Relational algebra and calculus Structured Query Language (SQL) Structured English-like … (SEQUEL)

Dr. Deepak B Phatak11 IIT BOMBAY CS634-Session 3 Relational Model Relational model A relation is a set of n-tuples Rows in a table Each relation has a schema List of attributes Similar to column headers in a table

Dr. Deepak B Phatak12 IIT BOMBAY CS634-Session 3 Relational Model Sample relation schema Student = (sroll, sname, sh, sr, scpi) Course = (ccode, cname, ccredit) Reg = (sroll, ccode, grade)

Dr. Deepak B Phatak13 IIT BOMBAY CS634-Session 3 Relational Model Student relation Student Set Course Set … … … … … … Number of elements = no. of students - Each element is a 5-tuple

Dr. Deepak B Phatak14 IIT BOMBAY CS634-Session 3 Relational Model Student relation as a Table srollsname sh Ajay Shah Nandan Nilekani 08 … … …

Dr. Deepak B Phatak15 IIT BOMBAY CS634-Session 3 Relational Model Relational algebra A relation is an element Operators are defined over relation(s) A relational operation results in a new relation having Different set of rows Different schema (may be) Or both

Dr. Deepak B Phatak16 IIT BOMBAY CS634-Session 3 Relational Model Keys Super key: A set of attributes that uniquely characterizes a specific n-tuple Candidate key: minimal super key Primary key: chosen candidate key

Dr. Deepak B Phatak17 IIT BOMBAY CS634-Session 3 Relational Model Examples of keys Student (sroll, sname, sh, sr, scpi) Superkeys: (unique entity identifier) Sroll; Sroll + sname; Sh + sr; Sroll + sh + sr; … Candidate keys are reduced minimal superkeys Sroll; sh + sr (single occupancy assumption) Primary key: sroll (practical choice)

Dr. Deepak B Phatak18 IIT BOMBAY CS634-Session 3 Relational Model Sample relation sroll snamesh Vijay Ambre02 srscpi D15034Parag Samarth Arul Menezes Ajay Shah Rajan Tambe

Dr. Deepak B Phatak19 IIT BOMBAY CS634-Session 3 Relational Model Sample relation srollsnamesh Vijay Ambre 02 sr 01D15034 Shaukat Ali08 scpi Arul Menezes Ajay Shah Rajan Tambe Sanjay Mistry

Dr. Deepak B Phatak20 IIT BOMBAY CS634-Session 3 Relational Model Sample relation srollsnamesh Vijay Ambre 02 sr 01D15034 Shaukat Ali08 scpi Arul Menezes Ajay Shah Rajan Tambe Sanjay Mistry

Dr. Deepak B Phatak21 IIT BOMBAY CS634-Session 3 Relational Model Relations If any value in a table (or a file) changes (add, delete, update), such a change can be made in the same table or file However, a relational operation results in a new relation Relational algebra operations are used to extract meaningful information from one or more relations Can be directly mapped into SQL

Dr. Deepak B Phatak22 IIT BOMBAY CS634-Session 3 Relational Model Relational algebra operators Selection Get rows from a relation Projection Get columns from a relation Cross product Combine rows from multiple relations Join Get meaningful information from the cross product

Dr. Deepak B Phatak23 IIT BOMBAY CS634-Session 3 Relational Model Selection Extracts n-tuples from a relation R, based on a predicate (condition) P R1 =  p (R) R1: has the same schema as that of R P: valid condition on R

Dr. Deepak B Phatak24 IIT BOMBAY CS634-Session 3 Relational Model Selection R1 =  scpi > 9 AND sh = 3 (student) The resulting relation will have one row [ arul menezes ] SQL query for this relational operation can be written as Select * From student Where scpi > 9 and sh = 3; ‘*’ means select ALL attributes of the schema

Dr. Deepak B Phatak25 IIT BOMBAY CS634-Session 3 Relational Model Projection Projects only specified attributes Given as a list R1 =  list (R) R1 has a new schema Cardinality (no of rows) ?

Dr. Deepak B Phatak26 IIT BOMBAY CS634-Session 3 Relational Model Projection R1 =  cname, ccredit (course) SQL query can be written as Select cname, ccredit from Course; cname ccredit Information Systems 6 Data Mining 6 Professional Ethics in IT 3

Dr. Deepak B Phatak27 IIT BOMBAY CS634-Session 3 Relational Model Projection- another example R1 =  sh (student) SQL query: Select sh From student; How many elements would R1 have?

Dr. Deepak B Phatak28 IIT BOMBAY CS634-Session 3 Relational Model Projection example srollsname sh Vijay Ambre 02 sr 01D15034 Shaukat Ali08 scpi Arul menezes Ajay Shah Rajan Tambe

Dr. Deepak B Phatak29 IIT BOMBAY CS634-Session 3 Relational Model SQL implementation of projection Select distinct sh From student; Result: Sh 2 8 3

Dr. Deepak B Phatak30 IIT BOMBAY CS634-Session 3 Relational Model Expressions  Sname (  scpi >9 & sh = 8 (student)) Select sname From student Where scpi > 9 And sh = 8;

Dr. Deepak B Phatak31 IIT BOMBAY CS634-Session 3 Relational Model CROSS PRODUCT Operates on two relations R = R1 x R2 Concatenates each tuple of R1 with every tuple of R2 If there are M and N elements in the two relations, the resultant relation has M x N elements Schema of R is concatenation of the two schemas of R1 and R2 R1.A1, R1.A2, …, R2.A1, …, etc..

Dr. Deepak B Phatak32 IIT BOMBAY CS634-Session 3 Relational Model Example tables sroll sname Sunita Sarawagi Kesav Nori Muthukrishnan sroll ccode CS CS CS CS HS Student Reg

Dr. Deepak B Phatak33 IIT BOMBAY CS634-Session 3 Relational Model Cross product sroll sname Reg.sroll ccode Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi HS Kesav Nori CS Kesav Nori CS Kesav Nori CS634 - Student X Reg (First 8 Rows)

Dr. Deepak B Phatak34 IIT BOMBAY CS634-Session 3 Relational Model Cross product sroll sname sroll ccode Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi HS Kesav Nori CS Kesav Nori CS Kesav Nori CS634 - Student X Reg (First 8 Rows)

Dr. Deepak B Phatak35 IIT BOMBAY CS634-Session 3 Relational Model Join Join is defined to get meaningful set of rows from a cross product R =  ρ (R1 X R2) Selection predicate provides for meaningful information extraction Two categories of join Natural join Theta join

Dr. Deepak B Phatak36 IIT BOMBAY CS634-Session 3 Relational Model Natural join Ensures equality of values of all common attributes Result schema is union of two schemas R = r1 |x| r2 R = student |X| reg R =  student.Sroll =reg.Sroll (student X reg)

Dr. Deepak B Phatak37 IIT BOMBAY CS634-Session 3 Relational Model sroll sname sroll ccode Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi CS Sunita Sarawagi HS Kesav Nori CS Kesav Nori CS Kesav Nori CS634 Cross product Student X Reg (First 8 Rows)

Dr. Deepak B Phatak38 IIT BOMBAY CS634-Session 3 Relational Model SQL query for natural join Select * from student natural join reg; Select * from student, reg Where student.Sroll = reg.Sroll;

Dr. Deepak B Phatak39 IIT BOMBAY CS634-Session 3 Relational Model Natural join schema sroll sname sroll ccode Sunita Sarawagi CS Sunita Sarawagi IT Kesav Nori IT Kesav Nori CS Muthukrishnan HS412 - Student |X| Reg

Dr. Deepak B Phatak40 IIT BOMBAY CS634-Session 3 Relational Model Theta join R = R1 |x|  R2 Theta is any (meaningful) predicate Usually has a “join” condition R =   (R1 x R2) R = student |x|  reg  : student.sroll = reg.sroll and scpi > 9 and sh = 8

Dr. Deepak B Phatak41 IIT BOMBAY CS634-Session 3 Relational Model SQL query for  join Select * from student, reg Where Student.Sroll = reg.Sroll and scpi > 9 and sh = 8;