Case Study Dbms Final
Case Study Dbms Final
Case Study Dbms Final
Relational Calculus.
A Case Study
Submitted by
BACHELOR OF ENGINEERING
IN
COMPUTER SCIENCE
Chandigarh University
Background-
Relational calculus, a foundational area of mathematical logic, is the source of relational calculus, a formal
language used in relational databases. Propositions are the subject of predicate calculus, where predicates
are truth-valued functions with arguments that produce statements known as propositions that may or may
not be true. comprehension relational calculus's goal—to give users an organized way to express queries in
relational databases—requires a solid understanding of its foundation.
Relational calculus is based on the relational model of data, which was first presented by Edgar F. Codd in
1970. With this structure, data is arranged into sets of tuples within relations, much like in database tables.
A record is represented by each tuple, and an attribute is a particular property. Relational calculus functions
within this architecture as its foundation.
Theoretical Framework -
The relational calculus is not the same as that of differential and integral calculus in mathematics but takes
its name from a branch of symbolic logic termed as predicate calculus.
When applied to databases, it is found in two forms. These are
• Tuple relational calculus which was originally proposed by Codd in the year 1972 and
• Domain relational calculus which was proposed by Lacroix and Pirotte in the year 1977
In first-order logic or predicate calculus, a predicate is a truth-valued function with arguments. When we
replace with values for the arguments, the function yields an expression, called a proposition, which will
be either true or false.
Tuple Relational Calculus (TRC)
It is a non-procedural query language which is based on finding a number of tuple variables also known as
range variable for which predicate holds true. It describes the desired information without giving a specific
procedure for obtaining that information. The tuple relational calculus is specified to select the tuples in a
relation. In TRC, filtering variable uses the tuples of a relation.
The result of the relation can have one or more tuples.
Notation:
For example:
Output: This query selects the tuples from the AUTHOR relation. It returns a tuple with 'name'
from Author who has written an article on 'database'.
Domain Relational Calculus (DRC)
The second form of relation is known as Domain relational calculus. In domain relational calculus, filtering
variable uses the domain of attributes. Domain relational calculus uses the same operators as tuple calculus.
It uses logical connectives ∧ (and), ∨ (or) and ┓ (not). It uses Existential (∃) and Universal Quantifiers (∀)
to bind the variable. The QBE or Query by example is a query language related to domain relational
calculus.
Notation:
Where a1,a2 are attributes P stands for formula built by inner attributes.
For example:
Output: This query will yield the article, page, and subject from the relational javatpoint, where
the subject is a database.
Implementation
Let's take an example of a Customer Database and try to see how TRC expressions work.
Customer Table
Customer_id Name Zip
code
1 Rohit 12345
2 Rahul 13245
3 Rohit 56789
4 Amit 12345.
Example 1: Write a TRC query to get all the data of customers whose zip
code is 12345.
Workflow of query - The tuple variable "t" will go through every tuple of
the Customer table. Each row will check whether the Cust_Zipcode is 12345
or not and only return those rows that satisfies the Predicate expression
condition.
The TRC expression above can be read as "Return all the tuple which
belongs to the Customer Table and whose Zipcode is equal to 12345."
Customer_id
1
2
3
4
Domain Relational Calculus (DRC)
Domain Relational Calculus uses domain Variables to get the column values required from the
database based on the predicate expression or condition.
{<x1,x2,x3,x4...> \| P(x1,x2,x3,x4...)}
where,
<x1,x2,x3,x4...> are domain variables used to get the column values required, and P(x1,x2,x3...) is
predicate expression or condition.
Let's take the example of Customer Database and try to understand DRC queries with some examples.
Customer Table
Customer_id Name Zip_code
1 Rohit 12345
2 Rahul 13245
3 Rohit 56789
4 Amit 12345
Example 1: Write a DRC query to get the data of all customers with Zip_code 12345.
Workflow of Query: In the above query x1,x2,x3 (ordered) refers to the attribute or column which we
need in the result, and the predicate condition is that the first two domain variables x1 and x2 should be
present while matching the condition for each row and the third domain variable x3 should be equal to
12345.