How to convert sql to relational algebra?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saltedfish
    New Member
    • Sep 2010
    • 2

    #1

    How to convert sql to relational algebra?

    Now I have a sql needed to be converted to relational algebra. There are two tables: student and sc.
    student has sno, sname, sage.
    sc has sno, cno, grade.
    How to translate the sql into relational algebra:
    select sname from student where sage > 20 or sno in (select sno from sc where grade > 90);

    I know it can be converted to union opertaion, but that is too complicated for many sqls like this. Are there any other methods?
    I have a plan of sql server, but I could not understand what it means?
    Any help with this would be great.
    Attached Files
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    I'm not sure what you're actually asking as I have no idea what SC might refer to as a table and I haven't come across the term Relational Algebra. That said you may be looking for something like :
    Code:
    SELECT   tS.SNo
           , [SName]
    FROM     [Student] AS tS
             LEFT OUTER JOIN
             [SC]
      ON     tS.SNo = SC.SNo
    WHERE   (tS.SAge > 20)
       OR   (MAX(SC.Grade) > 90)
    GROUP BY tS.SNo

    Comment

    • saltedfish
      New Member
      • Sep 2010
      • 2

      #3
      First thank you very much for you reply.
      I have unload a picture about the relational algebra.
      In fact, there are three tables: student, sc, course.
      course has cno and cname, respectively representing the number and name of course. sc has sno, cno, grade, respectlively representing number of student, number of course and the score.
      What I mean is this:
      Code:
      select sname 
            from student 
            where sage > 20 or 
                  sno in (select sno from sc where grade > 90)
      It is equal to:
      Code:
           select sname from student where sage > 20
           union
           select sname from student 
             where sno in (select sno from sc where grade > 90)
      Can it be expressed as like this:
      Code:
          select sname 
          from student,(select sno from sc where grade > 90) ta
          where sage > 20 or student.sno = ta.sno
      Maybe there has exists predicate:
      Code:
         select sname from student
         where sage > 20 or
               sno in (select sno from sc where grade > 90) or
               exists (select * from course)
      I don't care what the sqls means, but I only care how the sqls are translated to relational algebra.

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Hi Saltedfish. What you ask is related to a course assignment and is beyond what we can assist you with. We normally deal with expressing queries in Structured Query Language form, not in reverse-engineering these back to an academic form of logic such as relational algebra (see http://en.wikipedia.org/wiki/Relational_algebra).

        I studied predicate calculus many years ago, but even so I don't think this forum is the place for what you are asking. You are asking us to take a SQL-based implementation of relationships between tables and convert that back to its relational algebra equivalent.

        Even if we were experts on this - and I for one am not - we cannot do your work for you when it comes to academic coursework.

        -Stewart

        Comment

        Working...