CONSIDER THE TABLE:
ID |
NAME |
DEPT_NAME |
SALARY |
1 |
RAM |
IT |
50000 |
2 |
SHYAM |
FINANCE |
50000 |
3 |
SITA |
HR |
60000 |
4 |
HARI |
IT |
30000 |
5 |
JOHN |
FINANCE |
40000 |
6 |
ROY |
MANAGEMENT |
90000 |
7 |
LOK |
HR |
20000 |
Select Operator
Employee(ID,Name,Dept_Name, Salary)
Solution:
σ Dept_Name=”Finance” (Employee)
ID |
NAME |
DEPT_NAME |
SALARY |
2 |
SHYAM |
FINANCE |
50000 |
5 |
JOHN |
FINANCE |
40000 |
Employee(ID,Name,Dept_Name, Salary)
Solution:
σ salary > 50000 (Employee)
ID |
NAME |
DEPT_NAME |
SALARY |
3 |
SITA |
HR |
60000 |
6 |
ROY |
MANAGEMENT |
90000 |
Employee(ID,Name,Dept_Name, Salary)
Solution:
σ Dept_Name=”Finance” ∩salary > 50000 (Employee)
Employee(ID,Name,Dept_Name, Salary)
Solution:
σ salary >= 50000 and salary <=80000 (Employee)
Employee(ID,Name,Dept_Name, Salary)
Solution:
σ id>1 (Employee)
Project:
Employee(ID,Name,Dept_Name, Salary)
Solution:
Π ID,Name, Salary (Employee)
ID |
NAME |
SALARY |
1 |
RAM |
50000 |
2 |
SHYAM |
50000 |
3 |
SITA |
60000 |
4 |
HARI |
30000 |
5 |
JOHN |
40000 |
6 |
ROY |
90000 |
7 |
LOK |
20000 |
Employee(ID,Name,Dept_Name, Salary)
Solution:
Π Name(σ Dept_Name=”IT”(Employee)
NAME |
RAM |
HARI |
UNION
Software_Dev(EName, EID, Salary)
Project_Manager(EName,PID, Salary)
Solution:
Π Ename(Software_Dev) ∪ Π Ename(Project_Manager)
Instructor(ID,Name,Dept_Name,Salary)
Course(Course_ID,Title, Dept_Name, Credits)
Department(Dept_Name, Building, Budget)
Section(Course_ID,Sec_ID,Semester,Year,Building,Room_No,Time_Slot_ID)
Teaches(ID, Course_ID,Sec_ID,Semester,Year)
Students(ID, Name,Dept_Name,Tot_Cred)
Advisor(S_ID,I_ID)
Takes(ID,Course_ID, Sec_ID,Semester,Year, Grade)
Classroom(Building,Room_Number, Capacity)
Time_Slot(Time_Slot_ID,Day,Start_Time, End_Time)
Find the set of all courses(Course_ID) taught in the Fall 2009 semester , the spring 2010 semester or both.
Solution: here Section is the table which contain all attributes i.e. Course_ID, Year and Semester.
Set of all courses(Course_ID) taught in the Fall 2009 semester
ΠCourse_ID(σSemester=”Fall” ∩ year=2009(Section))
Set of all courses(Course_ID) taught in the Spring 2010 semester
ΠCourse_ID(σSemester=”Spring” ∩ year=2010(Section))
Set of all courses(Course_ID) taught in the Fall 2009 semester , the spring 2010 semester or both.
ΠCourse_ID(σSemester=”Fall”∩year=2009(Section))∪ ΠCourse_ID (σSemester=”Spring” ∩ year=2010(Section))
Software_Dev(EName, EID, Salary)
Project_Manager(EName,PID, Salary)
Solution:
Π Ename(Software_Dev) - Π Ename(Project_Manager)
Find all the courses taught in Fall 2009 semester but not in Spring 2010.
Solution: here Section is the table which contain all attributes i.e. Course_ID, Year and Semester.
Set of all courses(Course_ID) taught in the Fall 2009 semester
ΠCourse_ID(σSemester=”Fall” ∩ year=2009(Section))
Set of all courses(Course_ID) taught in the Spring 2010 semester
ΠCourse_ID(σSemester=”Spring” ∩ year=2010(Section))
Set of all courses(Course_ID) taught in the Fall 2009 semester , the spring 2010 semester or both.
ΠCourse_ID(σSemester=”Fall”∩year=2009(Section))- ΠCourse_ID (σSemester=”Spring” ∩ year=2010(Section))
Solution: here we will take Instructor and Advisor table
Π ID(Instructor)-Π ID(Advisor)
Solution: here we will take teaches table
Π ID(σSemester=”Spring” ∩ year=2020(teaches))-Π ID(Advisor)
Solution:
Here we take relation Instructor and Teaches
σDept_Name=”Physics”(Instructor X Teaches)
σDInstructor.ID=Teaches.ID(σDept_Name=”Physics”(Instructor X Teaches))
ΠName, Course_ID(σDInstructor.ID=Teaches.ID(σDept_Name=”Physics” (Instructor X Teaches)))
employee(name,salary,deptno) and department(deptno,deptname,address)
Write relational algebra for the following questions.
Solution: Π address(σemployee.deptno=department.deptno(employee X department))
Solution:
Π name(σ employee.deptno=department.deptno ∩ employee.name=department.deptname (employee X department))