Relational Calculus in DBMS with forms Domain and Tuple
Relational Calculus in Dbms with forms Domain and Tuple: Contrary to relational algebra that could be a procedural source language to fetch information and that conjointly explains however it’s done, relational Calculus is a non-procedural source language and has no description regarding how the query can work or the information can be fetched. It solely focuses on what to try and do, and not on a way to have it off.
Also See: Explain Keys in DBMS
Example:
Well, coming to the relational calculus then it can be described with an example of students who attend database course as below:
- Get all the details of the students such that each student has the course as ‘Database’. See the distinction between relational algebra and relational calculus here.
- From the primary one, we have a tendency to a clear on how to question and which relations to be queried. However the second tells what has to be done to induce the students with ‘database’ course.
- However, it will tell us how we want to proceed to attain this. Relational calculus is simply the explanative method of telling the query.
Relational Calculus in Dbms with forms Domain and Tuple
Relational calculus exists in two forms and those are mentioned below:
- Tuple relational calculus
- Domain relational calculus
Fig1: forms of relational calculus
-
Tuple relational calculus
A tuple relational calculus may be a non-procedural query language that specifies to pick out the tuples in a very relation. It will choose the tuples with vary of values or tuples for certain attribute values etc. The ensuing relation will have one or a lot of tuples. It’s denoted as below:
- {t / P(t)} or {t / condition(t)}: this is conjointly called an expression of relational calculus, where t is the resulting tuples, P (t) is the condition accustomed fetch it.
- {t / EMPLOYEE (t) and t.SALARY > 10000}: implies that it selects the tuples from worker relation specified ensuing worker tuples can have remuneration bigger than ten thousand. It’s an example of choosing a spread of values.
- {t | EMPLOYEE (t) AND t.DEPT_ID = 10}: this chooses all the tuples of worker name who work for Department 10.
Also See: What is Cardinality in DBMS
The variable that is employed within the condition is termed a tuple variable. Within the above example t.SALARY and t.DEPT_ID are tuple variables. Within the 1st example above, we’ve such as the condition t.SALARY >10000. What is the meaning of it? For all the SALARY>10000, display the workers. Here the remuneration is termed as a bound variable. Any tuple variable with ‘For All’ (?) or ‘there exists’ (?) condition is named a bound variable. Here, for any variety of values of salary larger than ten thousand, the meaning of the condition remains identical. Bound variables are those ranges of tuple variables whose meaning won’t change if the tuple variable is replaced by another tuple variable.
In the second example, we’ve used DEPT_ID= 10. Which means just for DEPT_ID = 10 display worker details. Such variable is termed free variable. Any tuple variable without any ‘For All’ or ‘there exists’ condition is termed Free Variable. If we modify DEPT_ID during this condition to another variable, say EMP_ID, the meaning of the question changes. To Illustrate, if we modify EMP_ID = 10, then above it’ll end in a totally different result set. Free variables are those ranges of tuple variables whose meaning can change if the tuple variable is replaced by another tuple variable.
All the conditions utilized in the tuple expression are referred to as well-formed formula – WFF. All the conditions within the expression are combined by using logical operators like AND, OR and NOT, and qualifiers like ‘For All’ (?) or ‘there exists’ (?). If the tuple variables are all bound variables in a WFF is named closed WFF. In an open WFF, we are going to have a minimum of one free variable.
Also See: Set Operations in SQL
-
Domain relational calculus
In distinction to tuple relational calculus, domain relational calculus uses list of attribute to be hand-picked from the relation based on the condition. It’s same as TRC, however differs by choosing the attributes instead of choosing whole tuples. It’s denoted as below:
{< a1, a2, a3, … an > | P(a1, a2, a3, … an)}
Where:
- a1, a2, a3, … an are the attributes of relation
- P is the condition
Example:
For example, choose EMP_ID and EMP_NAME of workers who work for department 10.
- {<EMP_ID, EMP_NAME> | <EMP_ID,EMP_NAME> ? EMPLOYEE Λ DEPT_ID = 10 }
Get name of the department which Alex works for.
- {DEPT_NAME |< DEPT_NAME > ? DEPT Λ ? DEPT_ID (<DEPT_ID> ? EMPLOYEE Λ EMP_NAME = Alex)}
So it was all about Relational Calculus in DBMS with forms Domain and Tuple, if you liked it then please share it with your friends.
it’ll greate if you include some real examples