in Databases
1,717 views
1 vote
1 vote
What is the difference between procedural query language and non-procedural query language? Why Relation algebra is called procedural and TRC is called non-procedural?
in Databases
by
1.7k views

1 comment

In a procedural query language, like Relational Algebra, you write a query as an expression consisting of relations and Algebra Opertors, like join, cross product, projection, restriction, etc. Like in an arithmetical expression (e.g. 2 / (3 + 4)), the operators have an order (in the example, the addition is performed before the division). So for instance you join the results of two different projection, and then perform a restriction, etc. A language like this is called procedural since each expression establish a certain order of performing its operators.

On the contrary, query languages like Relational Calculus, and the well known SQL query language are called “non procedural” since they express the expected result only through its properties, and not the order of the operators to be performed to produce it. For instance, with an SQL expression like:

SELECT t1.b
FROM t1
WHERE t1.b > 10

we specify the we want all the tuples of relation t1 for which t1.b > 10 is true, and from these we want the value of t1.b, but we do not specify if first the projection must be performed, and then the restriction, or the restriction first and then the projection. Imagine a complex SQL query, with many joins, conditions, restrictions, etc. Many different orders of executing the query could be devised (and in effect the task of the query optimizer is that of devising an efficient order to perform these operations, so to transform this declarative query into a procedural one).

source: procedural VS non procedural

0
0

2 Answers

1 vote
1 vote

In simple words:

Relation Algebra is procedural because there we specify What we want, How we want the output with exact order of operations.

Where as Relational Calculus is a Abstract method for declaring Formal Lang. It just mentions What we want. It never describes how to compute that output.

Eg.

Relational Algebra

                                      $σsubject = "database" and   price = "50"(Books)$ 

Relational Calculus

                                     {${b.bookSubject | Books(b) \Lambda b.bookPrice = 50}$}

Output

Selects tuples from books where 'price' is 50. (RA)

Prints Subject of book having price 50. (RC)

edited by
0 votes
0 votes
procedural language means there is a procedure to get the output...

non-procedural language means there is no procedure to get the output...

in relational algebra, we are preparing the procedure to get the output ===> relational algebra is procedural language

 

in relational calculus, we are not preparing the procedure to get the output means some how we get the output but on output we select some tuples by giving conditions ===> relational calculus is non-procedural language

2 Comments

Please explain it with an example.
0
0

you want find minimum element of your list?

in C language, you have to write your own code.

but some other programming languages, you can get list.min, in this case you are not preparing a procedure to find it... somehow you are getting it.

 

this is not exactly, but i want to give some idea

0
0