sukhbir1996 sukhbir1996 - 3 years ago 120
MySQL Question

Convert SQL SELECT query to corresponding/equivalent relational algebra

I have to convert SQL into corresponding relational algebra.

SELECT * FROM student;


What will be its equivalent expression in relational algebra?

Answer Source

You don't define "relational algebra". (There are many variants.) You don't define "convert"/"correspond"/"equivalent".

"Equivalent expression" = expression with the same value?

An algebra expression with the same value as SELECT * FROM Student:

 Student

"Equivalent expression" = expression with corresponding tables & operators?

Some possible conversion rules:

An SQL FROM clause first RENAMEs columns C1,... of each table *table* with alias A to A.C1,.... (A table name with no alias is short for using the name as the alias.) Then it handles JOIN. Then it handles ON. (C that is a column of a table aliased to A is short for A.C.)

SQL                              Algebra

*table* T                        RENAME C1\A.C1,... *table*
*table1* CROSS JOIN *table2*     *table1* NATURAL JOIN *table2*
*table1* (INNER) JOIN *table2*   *table1* NATURAL JOIN *table2*
*table* ON *condition*           RESTRICT *condition* *table*

An SQL SELECT clause PROJECTs on desired columns then RENAMEs either per AS or to drop A.s. (Solitary * is short for a list of all columns. A.* is short for for a list of all columns starting A..)

SQL             Algebra

SELECT ...,A.Ci,...,A.Cj AS X,...
FROM *table* T

                RENAME ...,A.Ci\Ai,...,A.Cj\X,...
                    PROJECT ...,A.Ci,...,A.Cj,...
                        *table*

So

SELECT * FROM Student

is short for

SELECT Student.C1,... FROM Student Student

which converts to

RENAME ...,Student.Ci\Ci,...
    PROJECT ...,Student.Ci,...
        Student

Because SQL is such an irregular language, the more SQL expressions allowed the more rules. If you want simple SQL expressions to correspond to simple algebra expressions instead of bloated ones then rules can be added. The more your algebra is like SQL the simpler and fewer the rules.

(Algebra SELECT/RESTRICT doesn't correspond to an SQL SELECT clause. It corresponds to an SQL WHERE clause.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download