answersLogoWhite

0


Best Answer

Relational algebra

In order to implement a DBMS, there must exist a set of rules which state how the database system will behave. For instance, somewhere in the DBMS must be a set of statements which indicate than when someone inserts data into a row of a relation, it has the effect which the user expects. One way to specify this is to use words to write an `essay' as to how the DBMS will operate, but words tend to be imprecise and open to interpretation. Instead, relational databases are more usually defined using Relational Algebra.

Relational Algebra is :

  • the formal description of how a relational database operates
  • an interface to the data stored in the database itself
  • the mathematics which underpin SQL operations

Operators in relational algebra are not necessarily the same as SQL operators, even if they have the same name. For example, the SELECT statement exists in SQL, and also exists in relational algebra. These two uses of SELECT are not the same. The DBMS must take whatever SQL statements the user types in and translate them into relational algebra operations before applying them to the database.

Terminology
  • Relation - a set of tuples.
  • Tuple - a collection of attributes which describe some real world entity.
  • Attribute - a real world role played by a named domain.
  • Domain - a set of atomic values.
  • Set - a mathematical definition for a collection of objects which contains no duplicates.
Operators - Write
  • INSERT - provides a list of attribute values for a new tuple in a relation. This operator is the same as SQL.
  • DELETE - provides a condition on the attributes of a relation to determine which tuple(s) to remove from the relation. This operator is the same as SQL.
  • MODIFY - changes the values of one or more attributes in one or more tuples of a relation, as identified by a condition operating on the attributes of the relation. This is equivalent to SQL UPDATE.
Operators - RetrievalThere are two groups of operations:
  • Mathematical set theory based relations:

    UNION, INTERSECTION, DIFFERENCE, and CARTESIAN PRODUCT.

  • Special database operations:

    SELECT (not the same as SQL SELECT), PROJECT, and JOIN.

Relational SELECTSELECT is used to obtain a subset of the tuples of a relation that satisfy a select condition.

For example, find all employees born after 1st Jan 1950: SELECTdob '01/JAN/1950'(employee)

Relational PROJECTThe PROJECT operation is used to select a subset of the attributes of a relation by specifying the names of the required attributes.

For example, to get a list of all employees surnames and employee numbers: PROJECTsurname,empno(employee)

SELECT and PROJECTSELECT and PROJECT can be combined together. For example, to get a list of employee numbers for employees in department number 1:Figure : Mapping select and project Set Operations - semanticsConsider two relations R and S.
  • UNION of R and S

    the union of two relations is a relation that includes all the tuples that are either in R or in S or in both R and S. Duplicate tuples are eliminated.

  • INTERSECTION of R and S

    the intersection of R and S is a relation that includes all tuples that are both in R and S.

  • DIFFERENCE of R and S

    the difference of R and S is the relation that contains all the tuples that are in R but that are not in S.

SET Operations - requirementsFor set operations to function correctly the relations R and S must be union compatible. Two relations are union compatible if
  • they have the same number of attributes
  • the domain of each attribute in column order is the same in both R and S.
UNION ExampleFigure : UNION INTERSECTION ExampleFigure : Intersection DIFFERENCE ExampleFigure : DIFFERENCE CARTESIAN PRODUCTThe Cartesian Product is also an operator which works on two sets. It is sometimes called the CROSS PRODUCT or CROSS JOIN.

It combines the tuples of one relation with all the tuples of the other relation.

CARTESIAN PRODUCT exampleFigure : CARTESIAN PRODUCT JOIN OperatorJOIN is used to combine related tuples from two relations:
  • In its simplest form the JOIN operator is just the cross product of the two relations.
  • As the join becomes more complex, tuples are removed within the cross product to make the result of the join more meaningful.
  • JOIN allows you to evaluate a join condition between the attributes of the relations on which the join is undertaken.

The notation used is R JOINjoin condition S

JOIN ExampleFigure : JOIN Natural JoinInvariably the JOIN involves an equality test, and thus is often described as an equi-join. Such joins result in two attributes in the resulting relation having exactly the same value. A `natural join' will remove the duplicate attribute(s).
  • In most systems a natural join will require that the attributes have the same name to identify the attribute(s) to be used in the join. This may require a renaming mechanism.
  • If you do use natural joins make sure that the relations do not have two attributes with the same name by accident.
OUTER JOINsNotice that much of the data is lost when applying a join to two relations. In some cases this lost data might hold useful information. An outer join retains the information that would have been lost from the tables, replacing missing data with nulls.

There are three forms of the outer join, depending on which data is to be kept.

  • LEFT OUTER JOIN - keep data from the left-hand table
  • RIGHT OUTER JOIN - keep data from the right-hand table
  • FULL OUTER JOIN - keep data from both tables
OUTER JOIN example 1Figure : OUTER JOIN (left/right) OUTER JOIN example 2Figure : OUTER JOIN (full)
User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is relational algebra in DBMS explain with suitable example?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Explain the select Operation in Relational Algebra with an example?

Relational Algebra - Example


Explain the different operations used in relational algebra with suitable examples?

This is a big question. I you enter 'relational algebra' in a search engine, you will find many sites which go over this. Wikipedia usually takes a very high level abstract approach. The link below seems fairly easy to understand.


Explain listing process with suitable example and Diagram?

1 Explain listing process with suitable example & Diagram


Can you explain algebra?

Algebra is using variables such as x to solve a problem. One example is x+3=8 in which x equals 5.


What do you mean by recursive function explain with suitable example?

Type your answer here...


Explain with suitable example how switch statement is differ from if statement?

www.assignmentsclub.com


2 Explain why navigation is simple in Relational Data Model than in Hierarchical?

Explain why nevigation is simple relational data model than in hirarchical model


Need of project for mca students?

EXplain the order and unorder lists with suitable example


Why do you use algebra in science?

Because equations are part of Science to explain the diversity of it. Example: H2o and other formulas....


Difference between database and relational database explain with example?

Database = Generic name for a system to store data Relational Database = A specific type of database that utilizes relationships between data to not only store the data but further its efficiency in its manipulation.


How can algebra be used to explain a geometric concept?

I am not sure


How do you explain that relational algebra operators can be composed and why the ability to compose operators is important?

In computer science, relational algebra is an offshoot of first-order logic and of algebra of sets concerned with operations over finitary relations, usually made more convenient to work with by identifying the components of a tuple by a name (called attribute) rather than by a numeric column index, which is what is called a relation in database terminology.The main application of relational algebra is providing a theoretical foundation for relational databases, particularly query languages for such databases, chiefly among which is SQLRelational algebra received little attention outside of pure mathematics until the publication of E.F. Codd's relational model of data in 1970. Codd proposed such an algebra as a basis for database query languages. (See section Implementations.)Both a named and a unnamed perspective are possible for relational algebra, depending on whether the tuples are endowed with component names or not. In the unnamed perspective, a tuple is simply a member of a Cartesian product. In the named perspective, tuples are functions from a finite set U of attributes (of the relation) to a domain of values (assumed distinct from U).[1] The relational algebras obtained from the two perspectives are equivalent.[2] The typical undergraduate textbooks present only the named perspective though,[3][4] and this article follows suit.Relational algebra is essentially equivalent in expressive power to relational calculus (and thus first-order logic); this result is known as Codd's theorem. One must be careful to avoid a mismatch that may arise between the two languages because negation, applied to a formula of the calculus, constructs a formula that may be true on an infinite set of possible tuples, while the difference operator of relational algebra always returns a finite result. To overcome these difficulties, Codd restricted the operands of relational algebra to finite relations only and also proposed restricted support for negation (NOT) and disjunction (OR). Analogous restrictions are found in many other logic-based computer languages. Codd defined the term relational completeness to refer to a language that is complete with respect to first-order predicate calculus apart from the restrictions he proposed. In practice the restrictions have no adverse effect on the applicability of his relational algebra for database purposes.AggregationFurthermore, computing various functions on a column, like the summing up its elements, is also not possible using the relational algebra introduced insofar. There are five aggregate functions that are included with most relational database systems. These operations are Sum, Count, Average, Maximum and Minimum. In relational algebra the aggregation operation over a schema (A1, A2, ... An) is written as follows:G1, G2, ..., Gm g f1(A1'), f2(A2'), ..., fk(Ak') (r)where each Aj', 1 ≤ j ≤ k, is one of the original attributes Ai, 1 ≤ i ≤ n.The attributes preceding the g are grouping attributes, which function like a "group by" clause in SQL. Then there are an arbitrary number of aggregation functions applied to individual attributes. The operation is applied to an arbitrary relation r. The grouping attributes are optional, and if they are not supplied, the aggregation functions are applied across the entire relation to which the operation is applied.Let's assume that we have a table named Account with three columns, namely Account_Number, Branch_Name and Balance. We wish to find the maximum balance of each branch. This is accomplished by Branch_NameGMax(Balance)(Account). To find the highest balance of all accounts regardless of branch, we could simply write GMax(Balance)(Account).Transitive closureAlthough relational algebra seems powerful enough for most practical purposes, there are some simple and natural operators on relations which cannot be expressed by relational algebra. One of them is the transitive closure of a binary relation. Given a domain D, let binary relation R be a subset of D×D. The transitive closure R+ of R is the smallest subset of D×D containing R which satifies the following condition: There is no relational algebra expression E(R) taking R as a variable argument which produces R+. This can be proved using the fact that, given a relational expression E for which it is claimed that E(R) = R+, where R is a variable, we can always find an instance r of R (and a corresponding domain d) such that E(r) ≠r+.[15]SQL however officially supports such fixpoint queries since 1999, and it had vendor-specific extensions in this direction well before that.