Table of contents | |
Introduction | |
Relational Algebra | |
Tuple Relational Calculus | |
Domain Relational Calculus | |
Sample Problems | |
Conclusion |
When it comes to managing and querying databases, Structured Query Language (SQL) is the most widely used language. However, there are other relational languages that can be employed in Database Management Systems (DBMS) to interact with databases. In this article, we will explore some of these languages and understand their basic concepts, syntax, and usage.
Relational Algebra is a procedural query language used to manipulate and retrieve data in relational databases. It consists of a set of operations that can be performed on relations to generate new relations. Some commonly used operations in Relational Algebra are:
(i) Selection: The selection operation is used to extract tuples from a relation based on specified conditions. It is denoted by the sigma symbol (σ). For example:
σ(age > 30)(Employees)
This code snippet selects all the employees from the "Employees" relation who are older than 30.
(ii) Projection: The projection operation is used to select specific attributes from a relation while discarding the rest. It is denoted by the pi symbol (π). For example:
π(name, age)(Employees)
This code snippet selects only the "name" and "age" attributes from the "Employees" relation.
(iii) Join: The join operation is used to combine tuples from two or more relations based on a common attribute. It is denoted by the cross (×) symbol. For example:
Employees × Departments
This code snippet joins the "Employees" and "Departments" relations based on the common attribute "department_id."
(iv) Union: The union operation is used to combine tuples from two relations without any duplicate entries. It is denoted by the U symbol. For example:
Employees U Managers
This code snippet combines the tuples from the "Employees" and "Managers" relations while eliminating any duplicate entries.
Tuple Relational Calculus is a non-procedural query language used to specify queries in terms of the tuples to be retrieved. It is based on the concept of first-order logic. Consider the following example:
{T | T ∈ Employees ∧ T.age > 30}
This code snippet retrieves all tuples from the "Employees" relation where the age is greater than 30.
Domain Relational Calculus is another non-procedural query language that specifies queries in terms of the attributes of the tuples to be retrieved. It is also based on the concept of first-order logic. Consider the following example:
{T.name | T ∈ Employees ∧ T.age > 30}
This code snippet retrieves only the "name" attribute from tuples in the "Employees" relation where the age is greater than 30.
Retrieve the names of all employees whose salary is greater than $50,000.
π(name)(σ(salary > 50000)(Employees))
Retrieve the names and ages of employees who belong to the "Sales" department.
π(name, age)(Employees × σ(department = "Sales")(Departments))
Retrieve the names of employees who do not have a manager.
π(name)(Employees - (π(manager)(Employees)))
While SQL is the dominant language in DBMS, understanding other relational languages such as Relational Algebra, Tuple Relational Calculus, and Domain Relational Calculus can provide a deeper understanding of the foundational principles of working with databases. These languages offer alternative ways to manipulate and query data, expanding your toolkit as a database professional.
75 videos|44 docs
|
|
Explore Courses for Software Development exam
|