<< Chapter < Page Chapter >> Page >
In this lecture, we will discuss the first formal languages for the relational models: Relational Algebra

In this lecture, we will discuss the first formal languages for the relational models: Relational Algebra

Relational algebra

Relational Algebra (RA) can be viewed as a data manipulation language for relational model. It consists of several basic operations which is enable user to specify retrieval requests. RA is called a procedural language in which user need to specify how to retrieve the expected data.

Relational Algebra has the following components:

  • Operands: Relations or Variables that represent relations
  • Operators that map relations to relations
  • Rules for combining operands and operators to relational algebra expression
  • Rules for evaluating those expressions

Operations of relational algebra include the followings:

  • Union, Intersect, Set Difference, Cartesian Product are operations based on set theory
  • Select, Project, Join, Division are operations developed especially for relational databases.
Example Database

Relational algebra operations from set theory

Definition: Two relations r(A1, A2, …, An) and s(B1, B2, …, Bn) are union compatible if they have the same degree n and dom(Ai) = dom(Bi) for 1 ≤ i ≤ n.

This mean two union compatible relations have the same number of attributes and each corresponding pair of attributes have the same domain

  1. UNION Operation

The UNION operation combines two union compatible relations into a single relation via set union of sets of tuples.

  • Notation: r1 r2 size 12{r1` union `r2`} {}
Union Operation Notation
  • r1 r2 = { t t r1 t r2 } size 12{r1` union `r2= lbrace t \lline t in r1 or t in r2 rbrace } {} where r1(R) and r2(R)
  • Result size: {} r1 r2 r1 + r2 size 12{ \lline r1` union `r2 \lline `<= ` \lline r1 \lline + \lline r2 \lline } {}
  • Result schema: R
  • Producing the result of UNION
    • Make a copy of relation r1
    • For each tuple t in relation r2, check whether it is in the result or not. If it is not already in the result then place it there.
  • Example:
Union Operation Example
  1. INTERSECTION Operation

The INTERSECTION operation combines two union compatible relations into a single relation via set intersection of sets of tuples.

  • Notation: r1 r2 size 12{r1` intersection `r2} {}
Intersection Operation Notation
  • r1 r2 = { t t r1 t r2 } size 12{r1` intersection `r2= lbrace t \lline t in r1 and t in r2 rbrace } {} where r1(R) and r2(R)
  • Result size: r1 r2 min ( r1 , r2 ) size 12{ \lline r1` intersection `r2 \lline `<= `"min" \( \lline r1 \lline , \lline r2 \lline \) rbrace } {}
  • Result schema: R
  • Producing the result of INTERSECTION
    • Initially, result set is empty
    • For each tuple t in relation r1, if t is in the relation r2 then place t in the result set.
  • Example
Intersection Operation Example
  1. SET DIFFERENCE Operation

The DIFFERENCE operation finds the set of tuples that exist in one relation but do not occur in the other union compatible relation

  • Notation: r1 \ r2
Difference Operation Notation
  • r1 = { t t r1 t r2 } size 12{r1`\`r2= lbrace t \lline t in r1` and `t notin r2 rbrace } {} where r1(R) and r2(R)
  • Result schema: R
  • Producing the result of the DIFFERENCE operation
    • Initially, result set is empty
    • For each tuple in r1, check whether it appear in r2 or not. If it does not then place it in the result set. Otherwise, ignores it
  • Example
Difference Operation Example
  1. CARTESIAN PRODUCT Operation

The PRODUCT operation combines information from two relations pairwise on tuples.

  • Notation: r x s
  • r × s = { ( t1 , t2 ) t1 r t2 s } size 12{r` times `s`=` lbrace \( t1`,`t2 \) ` \lline `t1 in r and `t2 in `s rbrace } {} where r(R) and s(S)
  • Each tuple in the result contains all attributes in r and s, possibly with some fields renamed to avoid ambiguity. The result set contains all possible tuple that can be construct from one tuple in r and one tuple in s.
  • Result schema: If we have R(A1, A2, …, An) and S(B1, B2, …, Bm) then the list of attributes in Result is (A1, A2, …, An, B1, B2, …, Bm)
  • Result size: r × s = r s size 12{ \lline r` times s \lline `=` \lline r \lline `*` \lline s \lline } {}
  • Producing the result of PRODUCT operation:
    • For each tuple in r, form new tuples by pair it with each tuple in s
    • Place all of these new tuples in the result set
  • Example

Questions & Answers

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Algebra. OpenStax CNX. Aug 17, 2012 Download for free at http://cnx.org/content/col11445/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Algebra' conversation and receive update notifications?

Ask