جبر رابطه ای در sql
در این بخش به بررسی چند مثال از جبر راطه ای می پردازیم.
مثال از Projection
مثال: جدول با عنوان E (for EMPLOYEE)
nr |
name |
salary |
1 |
John |
100 |
5 |
Sarah |
300 |
7 |
Tom |
100 |
SQL |
Result |
Relational algebra |
select salary from E
|
|
PROJECTsalary(E) |
select nr, salary from E
|
nr |
salary |
1 |
100 |
5 |
300 |
7 |
100 |
|
PROJECTnr, salary(E) |
بدون رکورد تکراری
Selection
The same table E (for EMPLOYEE) as above.
SQL |
Result |
Relational algebra |
select * from E where salary < 200
|
nr |
name |
salary |
1 |
John |
100 |
7 |
Tom |
100 |
|
SELECTsalary < 200(E) |
select * from E where salary < 200 and nr >= 7
|
|
SELECTsalary < 200 and nr >= 7(E) |
Note that the select operation in relational algebra has nothing to do with the SQL keyword select. Selection in relational algebra returns those tuples in a relation that fulfil a condition, while the SQL keyword select means "here comes an SQL statement".
Relational algebra expressions
SQL |
Result |
Relational algebra |
select name, salary from E where salary < 200
|
name |
salary |
John |
100 |
Tom |
100 |
|
PROJECTname, salary (SELECTsalary < 200(E))
or, step by step, using an intermediate result
Temp <- SELECTsalary < 200(E)
Result <- PROJECTname, salary(Temp)
|