sukhbir1996 - 3 years ago 120

MySQL Question

I have to convert SQL into corresponding relational algebra.

`SELECT * FROM student;`

What will be its equivalent expression in relational algebra?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

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 `RENAME`

s 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 `PROJECT`

s on desired columns then `RENAME`

s 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**