Relational Algebra Tutorial
21 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What SQL function is used to determine the total number of students enrolled?

  • MIN()
  • SUM()
  • COUNT() (correct)
  • MAX()
  • Which SQL operation would be used to find all major codes that students are registered in, ensuring that each code appears only once?

  • GROUP BY
  • COUNT(DISTINCT)
  • SELECT DISTINCT (correct)
  • JOIN
  • How would you retrieve the total balance of students grouped by their major code?

  • SELECT SUM(balance) GROUP BY mcode (correct)
  • SELECT MAX(balance) GROUP BY mcode
  • SELECT COUNT(balance) GROUP BY mcode
  • SELECT AVG(balance) GROUP BY mcode
  • To count how many students live in Beirut, which SQL query is appropriate?

    <p>COUNT(cityName) FROM Student WHERE cityName = 'Beirut'</p> Signup and view all the answers

    Which command would be used to delete all students that live in Beirut from the Student table?

    <p>DELETE FROM Student WHERE cityName = 'Beirut'</p> Signup and view all the answers

    What data is being retrieved for students whose balance is outside the range of 200 to 1000?

    <p>Student ids, names, and balance</p> Signup and view all the answers

    Which condition is used to filter out non CCE students from the data?

    <p>mcode ≠ 'CCE'</p> Signup and view all the answers

    Which majors are included in the query that retrieves student ids and names for specified major codes?

    <p>CCE, CC, and CS</p> Signup and view all the answers

    What is the purpose of the operation ∏(Major) - ∏(Student)?

    <p>Find majors that have no students enrolled</p> Signup and view all the answers

    Which SQL operation is used to get student information living in a specific city?

    <p>Select</p> Signup and view all the answers

    What does the symbol ∞ represent in the context of combining tables?

    <p>Outer join</p> Signup and view all the answers

    Which of the following queries retrieves the id, name, and city name of students?

    <p>∏(Student sid, fn, ln, cityName)</p> Signup and view all the answers

    Which filter must be applied to identify Computer Communication students living in Beirut?

    <p>cityName = 'Beirut' and mname = 'Computer Communication'</p> Signup and view all the answers

    What is the purpose of the projection operator in relational algebra when applied to the City relation?

    <p>To select specific attributes from the City relation</p> Signup and view all the answers

    Which relational algebra expression gets the list of cities with a population less than 200?

    <p>∏(cityId, cityName)(σ(population &lt; 200)(City))</p> Signup and view all the answers

    What does the selection operator do in the expression σ(balance ≥ 500 ∧ balance ≤ 5000)(Student)?

    <p>It filters students based on their balance</p> Signup and view all the answers

    How is the union of two relations represented in relational algebra?

    <p>∪</p> Signup and view all the answers

    Which statement describes the function of the expression R1 U R2 in the context of the student data?

    <p>It combines results from students with major code 'CC' and with a balance over 500</p> Signup and view all the answers

    In the context of relational algebra, what does the notation mcode = 'CC' signify in the student relation?

    <p>It specifies a filter for a particular major code</p> Signup and view all the answers

    What is the result of the expression σ(population > 100)(City)?

    <p>A list of cities with population greater than 100</p> Signup and view all the answers

    What attributes are retrieved by the expression ∏(sid, fn, ln, mcode, balance)(σ(mcode = 'CC' OR balance > 500)(Student))?

    <p>Students with a major code 'CC' and those with a balance greater than 500</p> Signup and view all the answers

    Study Notes

    Relational Algebra Tutorial

    • Schema:
      • City: (cityId, cityName, population)
      • Major: (mcode, mname, mcredits)
      • Student: (sid, fn, ln, balance, email, cityId*, mcode*)
        • denotes foreign key

    Queries

    • Get all cities:

      • Π(City)
    • Get cities with population > 100:

      • σ(population > 100) (City)
    • Get city IDs and names with population < 200:

      • Π (σ(population < 200)(City)) (cityId, cityName)
    • Get student IDs, names, major codes, and balances with balance between 500 and 5000 (inclusive): -Π(σ(500 ≤ balance ≤ 5000)(Student)) (sid, fn, ln, mcode, balance)

    • Get student IDs, names, major codes, and balances for CC students or students with balance > 500:

      • Π(σ(mcode = "CC" ∨ balance > 500)(Student)) (sid, fn, ln, mcode, balance)
    • Get student IDs, names, and balances where balance is not between 200 and 1000:

      • Π(σ(balance < 200 ∨ balance > 1000)(Student)) (sid, fn, ln, balance)
    • Get student IDs, names, and city names of all students:

      • Π(sid, fn, ln, cityName) (Student ∞ City)
    • Get student IDs, names, major codes, major names, and city names of non-CCE students:

      • Π (σ(mcode ≠ "CCE")(City ∞ Student ∞ Major)) (sid, fn, ln, S.mcode, mname, cityName)
    • Get student IDs, names, major codes, and names of all CCE, CC, and CS students:

      • Π (σ(mcode = "CCE" ∨ mcode = "CC" ∨ mcode = "CS")(Student)) (sid, fn, ln, mcode)
    • Get major codes of majors with no students:

      • Π(mcode) (Major) - Π(mcode) (Student)
    • Get student IDs and names of students living in Beirut:

      • Π (σ(cityName = "Beirut" ) (Student ∞ City)) (sid, fn, ln)
    • Get student IDs, names, and balances of Computer Communication students in Beirut: -Π (σ(cityName = "Beirut" ∧ mname = "Computer Communication")(City ∞ Student ∞ Major)) (sid, fn, ln, balance)

    • Get highest student balance:

      • S MAX(balance) (Student)
    • Get lowest balance of all CC students:

      • S MIN(balance) (σ(mcode = "CC")(Student))
    • Get total number of students:

      • S COUNT(*) (Student)
    • Get total number of students in Beirut - S COUNT(*) (σ(cityName="Beirut")(Student∞City))

    • Get major code total balance:

      • S SUM(balance) (Student)
    • Get total balance per major name:

      • S SUM(balance) (Student ∞ Major)
    • Get IDs and names of students with emails:

      • Π(sid, fn, ln) (σ(email ≠ NULL) (Student))
    • Get IDs and names of students without emails:

      • Π(sid, fn, ln) (σ(email = NULL) (Student))
    • Delete students living in Beirut:

      • student <- student - σ(cityName = "Beirut")(student ∞ city)
    • Add a new major:

      • major <- major U {("MEE", "mechatronics", 110)}
    • Get distinct major codes:

      • S COUNT(DISTINCT mcode) (Student)
    • Get total student count who own email:

      • S COUNT(email) (Student)
    • Get all major codes with students:

      • Π(DISTINCT mcode) (Student)

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Relational Algebra Tutorial PDF

    Description

    Explore the fundamentals of relational algebra through various queries and examples. This tutorial covers operations like selection and projection using schemas for cities, majors, and students. Test your understanding of how to manipulate and retrieve data effectively.

    More Like This

    Database Management System Quiz
    14 questions
    Relational Algebra in Database Management
    12 questions
    Database Systems: Relational Algebra
    10 questions
    Exercice Algèbre Relationnelle
    5 questions

    Exercice Algèbre Relationnelle

    CostEffectiveMetaphor8711 avatar
    CostEffectiveMetaphor8711
    Use Quizgecko on...
    Browser
    Browser