Relational Algebra and SQL

Relational Algebra and SQL

by Wentao Xie -
Number of replies: 0
The first part of the relational algebra contains select operator, project operator and the way to use both simultaneously. Select operator uses the greek sigma,σ, as the symble. For example, if we have a relation, "Student", and it has "ID", "Name", " GPA","HS"(high school size) and we want to pick up some rows that students who have GPA over 3.7, then we can write "σGPA > 3.7 Student". It is also alble for us to use logical operator "and", "^", to connect two conditions, for instance, we want to pick students who have GPA over 3.7 and whose high school size is bigger than 1000, we could write "σGPA > 3.7 ^ HS>1000 Student". So the basic format for using a select operator is "σCondition Relation".  Then we have project operator which is used to pick up the certain columns. Using the example above, if we were interest in all Students and their GPA, we can use the project operator to pick them up. The project operator uses the greek pi, π, as its symble. To express the query above, we can write "πName, GPA Student". Similarly the format is "πProjection Relation". Finally, we could use "()" to use select operator and projection operator together to pick up some specific items in the table of relation. For example, we only want the ID of the students whose GPA is greater than 3.7, we could write "πID (σGPA > 3.7 Student)".
The second part is about the Union operaor, Difference operator and Intersection operator. The concept of these operator is just similar as describing sets. When we want two lists from different realtion, we use the union operator. When we want to list the elements or the records that is in one list but not in another, we use difference operator. Natural Join symble is used in this case to connect two relations. And finally the intersection operator is used to find the common part of lists.

SQL progress:
SELECT, SELECT DISTINCT, WHERE, AND, OR, ORDER BY, INSTER INTO, UPDATE, DELETE. SELECT is to pick up the columns by specifying subtitle of the table. SELECT DISTINCT is to, when we have same elements in a column, print each elements once. WHERE help us to pick up rows or items by giving an expecting number or Key that may exists in the table. AND and OR are logical operators connecting two conditions. ORDER BY can help us to modify the output in certain order. INSERT INTO is used to insert new item, each new value should be claimed by using VALUE. UPDATE and DELETE do as these two words mean. (WARNING, when using DELETE, there is no  "undo", be careful!)