0% found this document useful (0 votes)
398 views2 pages

RAexample

The document provides examples of relational algebra queries on relations representing students, courses, and course registrations. The queries return information such as registered course codes and titles, unregistered course codes and titles, student names and registered course titles, student IDs registered for specific courses, and courses that all or all students of a specific major are registered for.

Uploaded by

Hina Kanwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
398 views2 pages

RAexample

The document provides examples of relational algebra queries on relations representing students, courses, and course registrations. The queries return information such as registered course codes and titles, unregistered course codes and titles, student names and registered course titles, student IDs registered for specific courses, and courses that all or all students of a specific major are registered for.

Uploaded by

Hina Kanwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Relational Algebra Examples: (Not: SQL sorgularını siz yazın)

Consider the following relations:


Student(ssn, name, address, major)
Course(code, title)
Registered(ssn,code)

1. List the codes of courses in which at least one student is registered (registered courses):

πcode ( Registered)

2. List the titles of registered courses (of those in 1.)

πcode ( Course ∞ Registered )


3. List the codes of courses for which no student is registered

πcode ( Course ) - πcode ( Registered ) Try: Students who are not registered to any courses.

4. The titles of courses for which no student is registered.


In the previous query we found the codes; natural join with Course to find the titles.

πname ( (πcode ( Course ) - πcode ( Registered )) ∞ Course)


5. Names of students and the titles of courses they registered to.

πname,title ( Student ∞ Registered ∞ Course)

or, can be written as πname,title ((σ1=4 ∧ 5=6 (Student x Registered x Course))

6. SSNs of students who are registered for ‘Database Systems’ or ‘Analysis of Algorithms’.

πssn ( Student ∞ Registered ∞ (σ title=’Database Systems’ Course)) ∪


πssn ( Student ∞ Registered ∞ (σ title=’Analysis of Algorithms’ Course))
7. SSNs of students who are registered for both ‘Database Systems’ and ‘Analysis of Algorithms’.

πssn ( Student ∞ Registered ∞ (σ title=’Database Systems’ Course)) ∩


πssn ( Student ∞ Registered ∞ (σ title=’Analysis of Algorithms’ Course))
The name of those students:
A=πssn ( Student ∞ Registered ∞ (σ title=’Database Systems’ Course)) ∩
πssn ( Student ∞ Registered ∞ (σ title=’Analysis of Algorithms’ Course))
πname ( A ∞ Student) used A= instead of ρ( ) function.
8. List of courses in which all students are registered.
πcode, ssn ( Registered ) / πssn ( Student )

SQL: (başka türlü de yazılabilir, önerilerinizi bana email ile yazın)

SELECT code FROM Registered


GROUP BY code
HAVING count(*) = (select count(code) from Course)

9. List of courses in which all ‘ECMP’ major students are registered.

πcode, ssn ( Registered ) / πssn (σ major=’ECMP’ Student )

You might also like