Question

Write appropriate PL/SQL statements to create a procedure to check that no section has more students...

Write appropriate PL/SQL statements to create a procedure to check that no section has more students than the capacity of the classroom in which the section is scheduled. Display the course_id, sec_id, semester, year, building, and room_number for the sections that have more students than the capacity of the classroom in which the section is scheduled.   The following are the tables needed:

classroom (building, room_number, capacity)

section (course_id, sec_id, semester, year, building, room_number, time_slot_id)

takes (student_id, course_id, sec_id, semester, year, grade)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CREATE OR REPLACE PROCEDURE capacity
AS
BEGIN

WITH student_count AS
(
SELECT count(student_id) stud_count, sec_id
FROM   takes
GROUP BY course_id, sec_id, semester, year, grade
),
WITH Sec_Cap
(
SELECT sum(a.capacity) room_cap,b.sec_id
FROM   classroom JOIN section
ON (a.room_number = b.room_number
      AND a.building = b.building
)
)

SELECT a.course_id
       , a.sec_id
    , a.semester
    , a.year
    , a.building
    , a.room_number
   FROM section a
   JOIN student_count b ON (a.sec_id = b.sec_id)
   JOIN Sec_Cap c ON (    b.sec_id = a.sec_id
                       AND b.stud_count > c.room_cap )
END;       
       

Add a comment
Know the answer?
Add Answer to:
Write appropriate PL/SQL statements to create a procedure to check that no section has more students...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assume that the takes relation has not yet been defined. Give an SQL statement that adds...

    Assume that the takes relation has not yet been defined. Give an SQL statement that adds the takes relation to the database. Assume that: •Id is an integer •course_id is a string of up to10 characters. •sec_id should be a non-negative integer. •the semester is a one-character field, equal to either ‘F’ or ‘S’, and the •year is an integer. •grade can be null, but if not, it should be a letter in the string ‘ABCDF’. Your statement must ensure...

  • Database concepts Find the names and ids of the students who have taken at most one...

    Database concepts Find the names and ids of the students who have taken at most one course in the Spring 2010 semester. Notice, at most one means one or zero. So, the answer should include students who did not take any course during that semester The data: create table classroom     (building       varchar(15),      room_number        varchar(7),      capacity       numeric(4,0),      primary key (building, room_number)     ); create table department     (dept_name      varchar(20),      building       varchar(15),      budget      numeric(12,2) check (budget > 0),      primary key (dept_name)     ); create...

  • This is database system concept. 1.Find the ids of instructors who are also students using a...

    This is database system concept. 1.Find the ids of instructors who are also students using a set operation. Assume that a person is identified by her or his id. So, if the same id appears in both instructor and student, then that person is both an instructor and a student. Remember: set operation means union, intersect or set difference. 2.Find the ids of instructors who are also students using the set membership operator. 3.Find the ids of instructors who are...

  • SQL question, you can right-click the picture and select open in a new tab for a...

    SQL question, you can right-click the picture and select open in a new tab for a better-looking experience. Write an SQL query using the university schema to find the ID of each student who has never taken a course at the university. Do this using no subqueries and no set operations (use an outer join) University Schema student takes ID ID пате course_id sec id semester уеar grade dept_name tot_cred section course |department course id sec_id semester advisor course_id title...

  • Create sql queries to find the following miscrosoft access compatible commands please 9. Courses for which...

    Create sql queries to find the following miscrosoft access compatible commands please 9. Courses for which at least three students earned a grade of A, showing the grade and the course code 10. Semesters when the highest number of courses have been scheduled, showing the semester name and the number of sections 11. (Extra) Professors that are not students, and students that are not professors, showing their ID and SSN 12. (Extra) Semesters for which all courses are taught by...

  • Problem 1. Please create the following tables for UMBC bookstore’s textbook management system with appropriate primary...

    Problem 1. Please create the following tables for UMBC bookstore’s textbook management system with appropriate primary keys & foreign keys. Please include drop table statements with cascade constraints before your create table statements so it is easier to grade your create table statements. E.g., suppose you will create table tab1, tab2, including the following before creating them: Drop table tab1 cascade constraints; Drop table tab2 cascade constraints; Assumptions: Each teacher can teach one or more scheduled course sections. Each scheduled...

  • Consider the Schema diagram for a university database a. Find the IDs of all students who...

    Consider the Schema diagram for a university database a. Find the IDs of all students who have taken all of the CMPSC courses. Use the division operation. b. Do the same operation as in problem a, using only fundamental operations. student takes ID course id sec id semester 1er 4112 dept_name tot cred grade advisor section course_id sec id semester year building TOOM_10 time_slof_id course course id title dept name credits department dept name building budget time slot time slot...

  • Use the SQL statements provided to create your tables. Write one SQL statement for each of...

    Use the SQL statements provided to create your tables. Write one SQL statement for each of the following problems. You can only use the conditions listed in the tasks. E.g., in task 1, you cannot manually look up pid of Information Systems undergraduate program. Here is the given code: drop table textbook_schedule cascade constraints; drop table textbook_author cascade constraints; drop table schedule cascade constraints; drop table course cascade constraints; drop table textbook cascade constraints; drop table author cascade constraints; drop...

  • (MMU) has decided to consolidate the functionality of three small overlapping database systems, which support applications...

    (MMU) has decided to consolidate the functionality of three small overlapping database systems, which support applications for 1) teaching (e.g. instructor assignment and evaluation), for 2) registration (e.g. online course status, waiting lists), and for 3) student records (e.g. transcript generation) The resulting new system will support the following enterprise description: Professors and GTAs are assigned to teach the sections of each class being offered in a semester. At the end of the semester, they get a "team rating" (professors...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT