How to represent NULL in relational algebra

nullprojectionrelational-algebrarelational-theory

In the 3rd part of the question below:

Study the tables given below and write relational algebra expressions for the queries that follow.

STUDENT(+ROLLNO, NAME, AGE, GENDER, ADDRESS, ADVISOR)
COURSE(+COURSEID, CNAME, CREDITS)
PROFESSOR(+PROFID, PNAME, PHONE)
ENROLLMENT(+ROLLNO, +COURSEID, GRADE)

Primary keys are preceded by a +. ADVISOR is a foreign key referring to PROFESSOR table. ROLLNO and COURSEID in ENROLLMENT are also foreign keys referring to THE primary keys with the same name.

  1. Names of femal students
  2. Names of male students along with advisor name
  3. Roll Number and name of students who have not enrolled for any course.

How do I represent NULL marks in relational algebra?

I projected STUDENT NAME and ROLLNO after assigning COURSEID from ENROLLMENT table as

COURSEID = NULL

Is this valid?

Best Answer

There are no NULL values in relational algebra. Here you can use the antijoin operator ▷:

πROLLNO, NAME(STUDENT ▷ENROLLMENT)

that selects all records from STUDENT where the ROLLNO is not in ENROLLMENT.

In SQL there are NULL values. You may use a left outer join and select the rows where the courseid is NULL:

select STUDENT.ROLLNO, STUDENT.NAME
from STUDENT left outer join ENROLLMENT 
    on(STUDENT.ROLLNO=ENROLLMENT.ROLLNO)
where ENROLLMENT.COURSEID is null
Related Question