Monday, May 12, 2014

Relational Model( Relational Algebra, Tuple calculus)

Relational model is used in database design mainly as the precursor of SQL and other query language. It is basically the overall theoretical model of database which is based on tuple and relations. It is based on the predicate logic.
Relational Algebra is a procedural query language.
The basic operations of Relational Algebra :
Select Operation :
Denoted by symbol  σ, the basic idea is to select certain tuples which satisfy a given predicate p. generally is of the form    σp  (R).
If we have a Library, then to select the book which is written by 'Korth' can be selected like this -

                                            σauthor =’korth’ (Library);

Project Operation :
This is to project attributes of certain table. Suppose we want only book title and author of the books of our library then we should write  - 
                                            book name, author (Library)

This will show only the said columns and nothing else. 
Combining projection and selection is commonest method to find out the desire result.

Rename operation:

Denoted by ρ, this is used to rename the output of the result, it may be an attribute or a whole relation itself.
 𝛒db/database(books)
Here the books named db is renamed as 'database' in the relation book.

Union Operation , Intersection Operation:
 This operations are more or less like the same as the name implied. The union operation is needed to union two tables. Union means total including both the tables.
Intersection gave an output a relation which shows the attributes common in both table. The region where two circles intersect , remember.
Both this operation are binary in nature. 

Other operations are like cartesian product, set difference,  etc.

Tuple Calculus:

A query in the tuple relational calculus is expressed as

  1.  i.e. the set of tuples  for which predicate  is true.
You can do any operation of relation algebra using tuple calculus. I personally prefer relational algebra than tuple calculus.






References  : 

No comments:

Post a Comment

Feautured Post

Python Trivia Post: enumerate()

Python has a very useful inbuilt function, which is called enumerate(). This is needed whenever you need the numbering of a certain element...