Before we startRecall that arelationor table, consists...

This preview shows page 1 - 8 out of 29 pages.

Databases - Relational AlgebraJianxin LiSchool of Computer Science & Software EngineeringUniversity of Western AustraliaJianxin Li (UWA)Relational Algebra1 / 28
Before we startRecall that arelation(or table), consists of:Aschemawhich is an ordered list ofattributes, with each attributecomposed ofnameand adomain(ortype).You can think of this as theheader rowfor the tableA set oftuples(or rows), where each entry is a value of the appropriatetype or the special valueNULL.Jianxin Li (UWA)Relational Algebra2 / 28
Example relations IConsider a relationStudentwith three attributesidof typeCHAR(8)nameof typeVARCHAR(64)genderof typeENUM("M", "F", "X")and a relationGradealso with three attributesidof typeCHAR(8)unitof typeCHAR(8)gradeof typeINTJianxin Li (UWA)Relational Algebra3 / 28
Example relations IIidnamegender12345678Ebenezer ScroogeM12345682Jane AustenF12345689JMartin ChuzzlewitMidunitgrade12345678CITS14028812345678CITS22117512345682CITS14029112345682CITS22117112345689CITS140255Jianxin Li (UWA)Relational Algebra4 / 28
Relational AlgebraRelational algebra is themathematical languagedescribing themanipulationof relationswhile SQL is an approximation to relational algebra.There are two fundamental operatorsSelectiondenoted byσ(sigma)This operatorselectsa subset of the rows satisfying some conditionProjectiondenoted byπ(pi)This operatorprojectsonto a desired subset of the columnsJianxin Li (UWA)Relational Algebra5 / 28
SelectionConsider the expressionσgrade>80GradeThis checkseach rowand keeps only the rows that satisfy the condition.The result isanother relationwith the same schema, but fewer rows.idunitgrade12345678CITS14028812345682CITS140291Jianxin Li (UWA)Relational Algebra6 / 28
ProjectionConsider the expressionπidStudentThis goes through each row, and only keeps thespecified columns.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture