Experiment Using Postgresql DBMS: Exercise 1
Experiment Using Postgresql DBMS: Exercise 1
Exercise 1:
Given a database with relations as follow:
Lecturers:
Projects:
Participation:
Requirements:
©Copyright by phuongnh
1
A. Create a database named QLKH, create above tables and insert data. Notice: Two attributes
IDL and IDP in table Participation refer attributes which have the same names in Lecturers and
Projects.
D.
1. Create two login accounts for Ngo Tuan Phong (username: phongnt, password:
phong123), and Nguyen Hong Phuong (username: phuongnh, password: phuong123).
These two lecturers have access rights onto QLKH database, described as follows:
• Ngo Tuan Phong has right to SELECT in Lecturers and Participants table.
• Nguyen Hong Phuong has right to create tables, views in database.
2. Create privilege group with all rights on all database objects for Vu Tuyet Trinh and Tran
Duc Khanh
©Copyright by phuongnh
2
Exercise 2:
Write the following queries in SQL. No duplicates should be printed in any of the answers.
1. Find the name of all juniors (level = JR) who are enrolled in a class taught by I. Teach.
2. Find the age of the oldest student who is either a History major or enrolled in a course
taught by I. teach.
3. Find the names of all classes that either meet in room R128 or have five or more students
enrolled.
4. Find the names of all students who are enrolled in two classes that meet at the same time.
5. Find the names of faculty members who teach in every room in which some class is
taught.
6. Find the names of faculty members for whom the combined enrollment of the courses
that they teach is less than five.
7. Print the level and the average age of students for that level, for each level.
8. Print the level and the average age of students for that level, for all levels except JR
9. For each faculty member that has taught classes only in room R128, print the faculty
member's name and the total number of classes she or he has taught.
10. Find the names of students enrolled in the maximum number of classes.
11. Find the names of students not enrolled in nay class.
12. For each age value that appears in Students, find the level value that appears most often.
For example, if there are more FR level students aged 18 than SR, JR, or SO students
aged 18, you should print the pair (18, FR).
©Copyright by phuongnh
3