0% found this document useful (0 votes)
6 views7 pages

Assumed RDatabase Schema

The document outlines various relational algebra queries based on a database schema involving students, courses, and enrollments. It includes operations such as selection, projection, joins, and set operations, providing examples for each type of query. Additionally, it presents advanced questions with answers related to student enrollment and course offerings.

Uploaded by

upretyaarogya977
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Assumed RDatabase Schema

The document outlines various relational algebra queries based on a database schema involving students, courses, and enrollments. It includes operations such as selection, projection, joins, and set operations, providing examples for each type of query. Additionally, it presents advanced questions with answers related to student enrollment and course offerings.

Uploaded by

upretyaarogya977
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Assumed Database Schema (Example)

STUDENT

SID Name Dept Age

COURSE

| CID | CName | Dept |

ENROLL

| SID | CID | Grade |

1. Basic Selection (σ)


Q1. Find all students belonging to the Computer department.

Relational Algebra:

σ Dept = 'Computer' (STUDENT)

Q2. Find students whose age is greater than 20.


σ Age > 20 (STUDENT)

2. Projection (π)
Q3. Display only student names and departments.
π Name, Dept (STUDENT)

Q4. List all course names offered.


π CName (COURSE)

3. Selection + Projection
Q5. Find n ames of students from IT department who are older than 21.
π Name ( σ Dept='IT' ∧ Age>21 (STUDENT) )

4. Cartesian Product (×)


Q6. Combine STUDENT and COURSE relations.
STUDENT × COURSE

(Usually avoided unless followed by selection)

5. Join Operations (⨝)


Q7. Find student details along with the courses they are enrolled in.
STUDENT ⨝ ENROLL

(Implicit join on SID)

Q8. Display student name and course name.


π Name, CName ( STUDENT ⨝ ENROLL ⨝ COURSE )

Q9. List students enrolled in Database course.


π Name ( σ CName='Database' ( STUDENT ⨝ ENROLL ⨝ COURSE ) )

6. Theta Join (⨝ condi

tion)
Q10. Find students whose department is same as the course department.
STUDENT ⨝ [Link] = [Link] COURSE

7. Rename (ρ)
Q11. Rename STUDENT relation as S.
ρ S (STUDENT)

Q12. Rename attribute Name as StudentName.


ρ (SID, StudentName, Dept, Age) (STUDENT)

8. Set Operations
Q13. Find students enrolled in Course A OR Course B.


π SID ( σ CID='A' (ENROLL) )

π SID ( σ CID='B' (ENROLL) )

Q14. Find students enrolled in both Course A AND Course B.


π SID ( σ CID='A' (ENROLL) )

π SID ( σ CID='B' (ENROLL) )

Q15. Find students enrolled in Course A but not Course B.


π SID ( σ CID='A' (ENROLL) )

π SID ( σ CID='B' (ENROLL) )

9. Division (÷) – Important Exam Question


Q16. Find students who are enrolled in all courses offered by the Computer
department.
π SID, CID (ENROLL)
÷
π CID ( σ Dept='Computer' (COURSE) )

10. Aggregate / Extended Relational Algebra


Q17. Count number of students in each department.
γ Dept, COUNT(SID) (STUDENT)

Q18. Find average age of students in IT department.


γ AVG(Age) ( σ Dept='IT' (STUDENT) )

11. Advanced / Exam-Oriented Questions


Q19. Find students who are not enrolled in any course.
π SID (STUDENT)

π SID (ENROLL)

Q20. Find courses that have no students enrolled.


π CID (COURSE)

π CID (ENROLL)

👉 Same schema is assumed:


STUDENT(SID, SName, Dept, Semester)
COURSE(CID, CName, Dept)
ENROLLMENT(SID, CID, Grade)

🔹 ADVANCED RELATIONAL ALGEBRA QUESTIONS


WITH ANSWERS

Q1. Find names of students who are enrolled in all CS department courses

Relational Algebra:

STUDENT ⨝
π SName (

(π SID (ENROLLMENT) ÷ π CID (σ Dept='CS' (COURSE)))


)

Answer:

SName
Ram

Q2. Find students who have NOT enrolled in any course


Relational Algebra:

π SID (STUDENT) − π SID (ENROLLMENT)

Answer:
No student (all students are enrolled)

Q3. Find students who scored grade A in more than one course

Relational Algebra (logical self-join):

σ [Link] = [Link] ∧ [Link] ≠ [Link]


π [Link] (

(ρ E1 (σ Grade='A' (ENROLLMENT)) ×
ρ E2 (σ Grade='A' (ENROLLMENT)))
)

Answer:

SID
S1

(Student Ram)

Q4. Find names of students who are enrolled only in CS department courses

Relational Algebra:

STUDENT ⨝
π SName (

(π SID (ENROLLMENT ⨝ σ Dept='CS' (COURSE))

π SID (ENROLLMENT ⨝ σ Dept='IT' (COURSE)))


Answer:

SName
Ram
Gita

Q5. Find courses that are taken by students from both CS and IT
departments

Relational Algebra:
π CID (ENROLLMENT ⨝ σ Dept='CS' (STUDENT))

π CID (ENROLLMENT ⨝ σ Dept='IT' (STUDENT))


Answer:

CID
C1

(DBMS)

Q6. Find students who have taken at least one course outside their own
department

Relational Algebra:

π SName (

(STUDENT ⨝ ENROLLMENT ⨝ COURSE)


σ [Link] ≠ [Link]

Answer:

SName
Ram

Q7. Find names of students who have taken both DBMS and Data Structure

Relational Algebra:

π SID (σ CName='DBMS' (ENROLLMENT ⨝ COURSE))

π SID (σ CName='Data Structure' (ENROLLMENT ⨝ COURSE))


Answer:

SID
S1

(Student Ram)

Q8. Find students whose semester is greater than any IT student’s semester

Relational Algebra (comparison logic):


π SName (
σ Semester > ALL
(π Semester (σ Dept='IT' (STUDENT)))
)

Answer:

SName
Ram

Q9. Find departments that offer courses but have no students enrolled

Relational Algebra:

π Dept (COURSE) − π Dept (STUDENT ⨝ ENROLLMENT ⨝ COURSE)

Answer:
None (all departments have enrolled students)

Q10. Find student names who have never scored grade B

Relational Algebra:

π SName (STUDENT)

π SName (STUDENT ⨝ σ Grade='B' (ENROLLMENT))


Answer:

SName
Sita
Hari

You might also like