You are on page 1of 2

Assignment #7

Roles and Privileges

Create two roles: REGISTRAR and INSTRUCTOR. Then create the following views and assign select rights on
each set of views to the roles they are listed under:
1. REGISTRAR
CURRENT_REGS: All students that have registered in the current day
SEATS_AVAIL: The remaining seats available in all sections (seats = capacity enrollment)
WEEK_REGS: All students that have registered in the last seven days
2. INSTRUCTOR
ROSTER: all students in classes taught. Assume that instructors have Oracle accounts that they
run the view from and that their login ids match their last names.
ASSIGNMENTS: all sections taught by the instructor
Finally, grant the registrar role to Mitch (murov_m) instructor role to Mitch (murov_m). This is my user id
which exists in the database in the labs. If you are working at home, you will have to create these users to
make sure your scripts work.
CREATE ROLE registrar;
CREATE ROLE instructor;
CREATE OR REPLACE VIEW current_regs AS
SELECT last_name, first_name
FROM student
WHERE TO_CHAR(TRUNC(registration_date), MM/DD/YYYY)= TO_CHAR(TRUNC (SYSDATE),
MM/DD/YYYY);
CREATE OR REPLACE VIEW seats_avail AS
SELECT s.course_no, c.description,
s.capacity-count(e.student_id) seatsavail
FROM
enrollment e, section s, course c
WHERE s.course_no = c.course_no
AND
e.section_id = s.section_id
GROUP BY s.course_no, c.description, s.capacity;
CREATE OR REPLACE VIEW week_regs AS
SELECT first_name, last_name
FROM student
WHERE registration_date between trunc(SYSDATE-7) and trunc(SYSDATE);
GRANT SELECT ON current_regs TO registrar;
GRANT SELECT ON seats_avail TO registrar;
GRANT SELECT ON week_regs TO registrar;
CREATE OR REPLACE VIEW roster AS
SELECT s.course_no course, s.section_no section, st.first_name first,
st.last_name last, e.student_id
FROM student st, enrollment e, section s, instructor i
WHERE st.student_id = e.student_id
AND e.section_id = s.section_id
AND s.instructor_id = i.instructor_id
AND i.last_name = user;
CREATE OR REPLACE VIEW assignments AS
SELECT RPAD(s.course_no,6) course, s.section_no section, c.description title
FROM section s, course c, instructor i
WHERE i.instructor_id = s.instructor_id
AND s.course_no = c.course_no
AND i.last_name = user;
GRANT SELECT ON roster TO instructor;
GRANT SELECT ON assignments TO instructor;

GRANT registrar TO qc210276


GRANT instructor TO qc210276

You might also like