SlideShare una empresa de Scribd logo
1 de 31
Relational Algebra Lecture 5
Relational Query Languages ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Algebra ,[object Object],[object Object],[object Object]
Relational Algebra ,[object Object],[object Object],[object Object],[object Object]
Relational Algebra in a DBMS parser SQL Relational algebra expression Optimized Relational algebra expression Query  optimizer Code generator Query execution plan Executable code DBMS
Select Operator ,[object Object],[object Object],1123  John  123 Main  stamps 1123  John  123 Main  coins 5556  Mary  7 Lake Dr  hiking 9876  Bart  5 Pine St  stamps 1123  John  123 Main  stamps 9876  Bart  5 Pine St  stamps Person Id  Name  Address  Hobby Id  Name  Address  Hobby
Selection Condition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],Selection Condition - Examples
Project Operator ,[object Object],1123  John  123 Main  stamps 1123  John  123 Main  coins 5556  Mary  7 Lake Dr  hiking 9876  Bart  5 Pine St  stamps John  stamps John  coins Mary  hiking Bart  stamps Id  Name  Address  Hobby  Name  Hobby Person
Project Operator 1123  John  123 Main  stamps 1123  John  123 Main  coins 5556  Mary  7 Lake Dr  hiking 9876  Bart  5 Pine St  stamps John  123 Main Mary  7 Lake Dr Bart  5 Pine St Result is a table (no duplicates) Id  Name  Address  Hobby Name  Address Person
Relational Expressions: Combining Operators 1123  John  123 Main  stamps 1123  John  123 Main  coins 5556  Mary  7 Lake Dr  hiking 9876  Bart  5 Pine St  stamps 1123  John 9876  Bart Id  Name  Address  Hobby  Id  Name Person
Set Operators ,[object Object],[object Object],[object Object]
Union Compatible Relations ,[object Object],[object Object],[object Object],[object Object],[object Object]
Example Tables: Person (SSN, Name, Address, Hobby) Professor (Id, Name, Office, Phone) are not union compatible.  However
Cartesian Product ,[object Object],[object Object],[object Object],[object Object],[object Object],a  b  c  d  a  b  c  d x1  x2  y1  y2  x1  x2  y1  y2 x3  x4  y3  y4  x1  x2  y3  y4 x3  x4  y1  y2 R   S   x3  x4  y3  y4 R   S
Renaming ,[object Object],[object Object],[object Object],[object Object]
Example This is a relation with 4 attributes:  StudId, SCrsCode, ProfId, PCrsCode
Derived Operation: Join The expression :    join-condition ´  (R    S)  where  join-condition ´  is a  conjunction  of terms: A i   oper B i in which  A i  is an attribute of  R,   B i  is an attribute of  S,  and  oper  is one of =, <, >,      ,   , is referred to as the (theta) join of  R  and  S  and denoted: R   join-condition   S Where  join-condition  and  join-condition ´  are (roughly) the same …
Join and Renaming ,[object Object],[object Object],[object Object],[object Object]
Theta Join – Example Output  the names of all employees that earn more than their managers.  Employee.Name  (Employee  MngrId=Id AND Salary>Salary   Manager) The join yields a table with attributes: Employee.Name, Employee.Id, Employee.Salary, MngrId Manager.Name, Manager.Id, Manager.Salary
Equijoin Join - Example  Name,CrsCode ( Student   Id=StudId   Grade=‘A’ (Transcript)) Id  Name  Addr  Status 111  John  …..  ….. 222  Mary  …..  ….. 333  Bill  …..  ….. 444  Joe  …..  ….. StudId  CrsCode  Sem  Grade 111  CSE305  S00  B 222  CSE306  S99  A 333  CSE304  F99  A Mary  CSE306 Bill  CSE304 The equijoin is commonly used since it combines related  data in different relations. Student Transcript Equijoin: Join condition is a conjunction of  equalities .
Natural Join ,[object Object],[object Object],[object Object],Transcript (StudId, CrsCode, Sem, Grade) Teaching (ProfId, CrsCode, Sem) Transcript  Teaching =    StudId, Transcript.CrsCode, Transcript.Sem, Grade, ProfId  ( Transcript  CrsCode=CrsCode AND Sem=Sem Teaching) [StudId, CrsCode, Sem, Grade, ProfId ]
Natural Join (con’t) ,[object Object],R S =   attr-list  (  join-cond  (R × S) ) where attr-list = attributes (R)    attributes (S) (duplicates are eliminated) and  join-cond  has  the form: A 1  = A 1   AND … AND  A n  = A n where  {A 1  … A n } = attributes(R)    attributes(S)
Natural Join Example ,[object Object], StudId  (   CrsCode    CrsCode2  ( Transcript  Transcript [StudId, CrsCode2, Sem2, Grade2])) (don’t join on CrsCode, Sem,  and Grade attributes)
Division ,[object Object],[object Object],[object Object],[object Object],[object Object]
Division (con’t)
Division - Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Schema for Student Registration System Student (Id, Name, Addr, Status) Professor (Id, Name, DeptId) Course (DeptId, CrsCode, CrsName, Descr) Transcript (StudId, CrsCode, Semester, Grade) Teaching (ProfId, CrsCode, Semester) Department (DeptId, Name)
Query Sublanguage of SQL ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],SELECT  C.CrsName FROM  Course C WHERE  C.DeptId = ‘CS’
Join Queries ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],SELECT  C.CrsName FROM  Course C, Teaching T WHERE  C.CrsCode=T.CrsCode  AND  T.Sem=‘S2000’  CrsName (Course  Sem=‘S2000’  (Teaching) )  CrsName  (  Sem=‘S2000’  (Course  Teaching) )
Correspondence Between SQL and Relational Algebra SELECT  C.CrsName FROM  Course C, Teaching T WHERE  C.CrsCode=T.CrsCode  AND  T.Sem=‘S2000’ Also equivalent to:  CrsName   C_ CrsCode=T_CrsCode AND Sem=‘S2000’ (Course [C_CrsCode, DeptId, CrsName, Desc ]     Teaching  [ ProfId, T_CrsCode, Sem ]) This is the simple evaluation algorithm for  SELECT . Relational algebra expressions are procedural.  Which of  the two equivalent expressions is more easily evaluated?

Más contenido relacionado

La actualidad más candente (20)

Json
JsonJson
Json
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Mysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sqlMysql Crud, Php Mysql, php, sql
Mysql Crud, Php Mysql, php, sql
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Java script
Java scriptJava script
Java script
 
Authentication and Authorization in Asp.Net
Authentication and Authorization in Asp.NetAuthentication and Authorization in Asp.Net
Authentication and Authorization in Asp.Net
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
 
Html Frames
Html FramesHtml Frames
Html Frames
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Intro to HTML and CSS basics
Intro to HTML and CSS basicsIntro to HTML and CSS basics
Intro to HTML and CSS basics
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Span and Div tags in HTML
Span and Div tags in HTMLSpan and Div tags in HTML
Span and Div tags in HTML
 

Destacado

Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbmsshekhar1991
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusemailharmeet
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overviewgourav kottawar
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebraRushdi Shams
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joinsMudasir Syed
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebraguest20b0b3
 

Destacado (7)

Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
Rrelational algebra in dbms overview
Rrelational algebra in dbms overviewRrelational algebra in dbms overview
Rrelational algebra in dbms overview
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
 
MySQL JOIN & UNION
MySQL JOIN & UNIONMySQL JOIN & UNION
MySQL JOIN & UNION
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 

Similar a Relational+algebra (1)

3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMSkoolkampus
 
Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languagesjamunaashok
 
Relation model part 1
Relation model part 1Relation model part 1
Relation model part 1Siti Ismail
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operationsSanthiNivas
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptRoshni814224
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Prosanta Ghosh
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMSkoolkampus
 
Mca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsMca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsRai University
 
Lecture-3 Relational Algebra I.pptx
Lecture-3 Relational Algebra I.pptxLecture-3 Relational Algebra I.pptx
Lecture-3 Relational Algebra I.pptxHanzlaNaveed1
 

Similar a Relational+algebra (1) (20)

Ra Revision
Ra RevisionRa Revision
Ra Revision
 
R Algebra.ppt
R Algebra.pptR Algebra.ppt
R Algebra.ppt
 
07.04 joins
07.04 joins07.04 joins
07.04 joins
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
relational algebra
relational algebrarelational algebra
relational algebra
 
Lllll
LllllLllll
Lllll
 
3. Relational Models in DBMS
3. Relational Models in DBMS3. Relational Models in DBMS
3. Relational Models in DBMS
 
Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languages
 
Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
Relation model part 1
Relation model part 1Relation model part 1
Relation model part 1
 
Relational algebra operations
Relational algebra operationsRelational algebra operations
Relational algebra operations
 
Details of RDBMS.ppt
Details of RDBMS.pptDetails of RDBMS.ppt
Details of RDBMS.ppt
 
relational model in Database Management.ppt.ppt
relational model in Database Management.ppt.pptrelational model in Database Management.ppt.ppt
relational model in Database Management.ppt.ppt
 
Lec02
Lec02Lec02
Lec02
 
3.ppt
3.ppt3.ppt
3.ppt
 
Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013Dbms ii mca-ch5-ch6-relational algebra-2013
Dbms ii mca-ch5-ch6-relational algebra-2013
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 
Mca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsMca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql concepts
 
Lecture-3 Relational Algebra I.pptx
Lecture-3 Relational Algebra I.pptxLecture-3 Relational Algebra I.pptx
Lecture-3 Relational Algebra I.pptx
 

Último

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Último (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

Relational+algebra (1)

  • 2.
  • 3.
  • 4.
  • 5. Relational Algebra in a DBMS parser SQL Relational algebra expression Optimized Relational algebra expression Query optimizer Code generator Query execution plan Executable code DBMS
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Project Operator 1123 John 123 Main stamps 1123 John 123 Main coins 5556 Mary 7 Lake Dr hiking 9876 Bart 5 Pine St stamps John 123 Main Mary 7 Lake Dr Bart 5 Pine St Result is a table (no duplicates) Id Name Address Hobby Name Address Person
  • 11. Relational Expressions: Combining Operators 1123 John 123 Main stamps 1123 John 123 Main coins 5556 Mary 7 Lake Dr hiking 9876 Bart 5 Pine St stamps 1123 John 9876 Bart Id Name Address Hobby Id Name Person
  • 12.
  • 13.
  • 14. Example Tables: Person (SSN, Name, Address, Hobby) Professor (Id, Name, Office, Phone) are not union compatible. However
  • 15.
  • 16.
  • 17. Example This is a relation with 4 attributes: StudId, SCrsCode, ProfId, PCrsCode
  • 18. Derived Operation: Join The expression :  join-condition ´ (R  S) where join-condition ´ is a conjunction of terms: A i oper B i in which A i is an attribute of R, B i is an attribute of S, and oper is one of =, <, >,   ,  , is referred to as the (theta) join of R and S and denoted: R join-condition S Where join-condition and join-condition ´ are (roughly) the same …
  • 19.
  • 20. Theta Join – Example Output the names of all employees that earn more than their managers.  Employee.Name (Employee MngrId=Id AND Salary>Salary Manager) The join yields a table with attributes: Employee.Name, Employee.Id, Employee.Salary, MngrId Manager.Name, Manager.Id, Manager.Salary
  • 21. Equijoin Join - Example  Name,CrsCode ( Student Id=StudId  Grade=‘A’ (Transcript)) Id Name Addr Status 111 John ….. ….. 222 Mary ….. ….. 333 Bill ….. ….. 444 Joe ….. ….. StudId CrsCode Sem Grade 111 CSE305 S00 B 222 CSE306 S99 A 333 CSE304 F99 A Mary CSE306 Bill CSE304 The equijoin is commonly used since it combines related data in different relations. Student Transcript Equijoin: Join condition is a conjunction of equalities .
  • 22.
  • 23.
  • 24.
  • 25.
  • 27.
  • 28. Schema for Student Registration System Student (Id, Name, Addr, Status) Professor (Id, Name, DeptId) Course (DeptId, CrsCode, CrsName, Descr) Transcript (StudId, CrsCode, Semester, Grade) Teaching (ProfId, CrsCode, Semester) Department (DeptId, Name)
  • 29.
  • 30.
  • 31. Correspondence Between SQL and Relational Algebra SELECT C.CrsName FROM Course C, Teaching T WHERE C.CrsCode=T.CrsCode AND T.Sem=‘S2000’ Also equivalent to:  CrsName  C_ CrsCode=T_CrsCode AND Sem=‘S2000’ (Course [C_CrsCode, DeptId, CrsName, Desc ]  Teaching [ ProfId, T_CrsCode, Sem ]) This is the simple evaluation algorithm for SELECT . Relational algebra expressions are procedural. Which of the two equivalent expressions is more easily evaluated?