Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring 2019. Use an explicit cursor to print out the titles and prices of textbooks for these two courses.
Sample code to create the tables:
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 table teacher cascade constraints;
drop table program cascade constraints;
create table program
(pid int, --- program id
pname varchar(50), --- program name
ptype int, --- program type (1: undergraduate, 2: graduate)
primary key (pid));
insert into program values(1, 'Information Systems', 1);
insert into program values(2, 'Information Systems', 2);
insert into program values(3, 'Human Centered Computing', 2);
create table teacher
(tid int,
tname varchar(50),
primary key (tid)
);
insert into teacher values(1,'Dr. Chen');
insert into teacher values(2, 'Dr. Karabatis');
insert into teacher values(3,'Komlodi');
insert into teacher values(4, 'Kuber');
insert into teacher values(5, 'Dr. Janeja');
insert into teacher values(6, 'Dr. Roy');
create table author
(
aid int,
aname varchar(50),
primary key (aid)
);
insert into author values
(1, 'Joel Murach');
insert into author values
(2, 'Dan Sullivan');
insert into author values
(3, 'Jeff Hoffer');
insert into author values
(4, 'Ramesh Venkataraman');
insert into author values
(5, 'Heikki Topi');
insert into author values
(6,'YVonne Rogers');
insert into author values
(7,'Helen Sharp');
insert into author values
(8,'Jenny Preece');
insert into author values
(9,'Ramez Elmasri');
insert into author values
(10,'Shamkant B. Navathe');
insert into author values
(11,'Mark A. Weiss');
--- add more
create table textbook
(
tbid int, --- text book
title varchar(50), ---- title of book
publisher varchar(50), --- publisher name
edition int, --- edition, e.g., 3 means 3rd edition
quantity int, --- number of copies in store
price number, --- price of the book
primary key (tbid)
);
insert into textbook values
(1, 'Oracle SQL and PL/SQL', 'Murach Press',2,100,50);
insert into textbook values
(2, 'NoSQL for Mere Mortals', 'Addison-Wesley',1,100,40);
insert into textbook values
(3, 'Modern Database Management','Pearson',12,100,225);
insert into textbook values
(4, 'Interaction Design','Wiley',3,30,45);
insert into textbook values
(5, 'Fundamentals of Database Systems', 'Pearson',7,30,153);
insert into textbook values
(6, 'Data Structures and Algorithm Analysis in C++', 'Addison-
Wesley',4,30,140);
create table course
(
cid int, --- course id
cname varchar(50), --- course name
pid int, --- program id
primary key (cid),
foreign key(pid) references program
);
insert into course values(1, 'IS 420: Database Application Development',1);
insert into course values(2, 'IS 410: Introduction to Database Design',1);
insert into course values(3, 'IS 620: Advanced Database Project',2);
insert into course values(4, 'IS 722: Database Integration',2);
insert into course values(5, 'HCC 629: Fundamentals of Human-Centered Computing',3);
insert into course values(6, 'HCC 729: Human-Centered Design',3);
insert into course values(7, 'IS 809: Computational Methods for IS Research',2);
create table schedule
(sid int, --- schedule id
cid int, --- course id
snumber int, --- section number
semester varchar(10), --- spring, fall, summer, winter,
year int, --- year of the class
tid int, --- teach id
num_registered int, --- number of registered students for this class section
primary key (sid),
foreign key (cid) references course,
foreign key(tid) references teacher
);
-- IS 420 scheduled fall 18 by Dr. Karabatis, 2 sections
insert into schedule values
(1,1,1, 'fall',2018,2,30);
insert into schedule values
(2,1,2, 'fall',2018,2,30);
--spring 19 2 sections by Dr. Chen
insert into schedule values
(3,1,1, 'spring',2019,1,30);
insert into schedule values
(4,1,2, 'spring',2019,1,30);
--- IS 620 scheduled for each semester one section
insert into schedule values
(5,3,1, 'fall',2018,1,40);
insert into schedule values
(6,3,1, 'spring',2019,2,40);
-- IS 410 scheduled for each semester
insert into schedule values
(7,2,1,'spring',2019,5,30);
insert into schedule values
(8,2,2,'spring',2019,5,30);
-- HCC 629 scheduled each semester
insert into schedule values
(9,5,1,'fall',2018,4,30);
insert into schedule values
(10,5,1,'spring',2019,3,30);
-- HCC 729 scheduled each year
insert into schedule values
(11,6,1,'fall',2018,4,20);
--- IS 809 scheduled once a year
insert into schedule values
(12,7,1,'fall',2018,6,20);
create table textbook_author
(
aid int, --- author id
tbid int, --- text book id
primary key(aid, tbid),
foreign key(aid) references author,
foreign key(tbid) references textbook
);
insert into textbook_author values
(1, 1);
insert into textbook_author values
(2, 2);
insert into textbook_author values
(3, 3);
insert into textbook_author values
(4, 3);
insert into textbook_author values
(5, 3);
insert into textbook_author values
(6, 4);
insert into textbook_author values
(7, 4);
insert into textbook_author values
(8, 4);
insert into textbook_author values
(9, 5);
insert into textbook_author values
(10, 5);
insert into textbook_author values
(11, 6);
create table textbook_schedule(
sid int, --- schedule id
tbid int, --- text book id
primary key(sid, tbid),
foreign key(sid) references schedule,
foreign key(tbid) references textbook
);
--- first 4 schdule use book 1 & 2
insert into textbook_schedule values(1,1);
insert into textbook_schedule values(1,2);
insert into textbook_schedule values(2,1);
insert into textbook_schedule values(2,2);
insert into textbook_schedule values(3,1);
insert into textbook_schedule values(3,2);
insert into textbook_schedule values(4,1);
insert into textbook_schedule values(4,2);
--- 620 use textbook 5
insert into textbook_schedule values(5,5);
insert into textbook_schedule values(6,5);
-- 410 use textbook 3
insert into textbook_schedule values(7,3);
insert into textbook_schedule values(8,3);
-- 629 use textbook 4
insert into textbook_schedule values(9,4);
insert into textbook_schedule values(10,4);
-- 809 use textbook 6
insert into textbook_schedule values(12,6);
commit;
Answer:
Cursor code:
set serveroutput ON; -- used to enable output on screen
DECLARE
book_title textbook.title%type;
book_price textbook.price%type;
CURSOR cr IS select title, price FROM textbook WHERE tbid IN(SELECT
tbid FROM textbook_schedule WHERE sid IN
(select s.sid from schedule s join course c
ON c.cid = s.cid
WHERE c.cname LIKE 'HCC 629%' AND s.semester = 'spring' AND s.year
= 2019))
UNION
select title, price FROM textbook
WHERE tbid IN(SELECT tbid FROM textbook_schedule WHERE sid IN
(select s.sid from schedule s join course c ON c.cid = s.cid
WHERE c.cname LIKE 'IS 620%'AND s.semester = 'spring' AND s.year =
2019));
BEGIN
OPEN cr; -- open cursor
LOOP
FETCH cr INTO book_title, book_price; -- everytime loop is
executed, the next row is copied into book_title and book_price
using FETCH command
EXIT when cr%NOTFOUND; -- implicit cursor is used for exit
condition
dbms_output.put_line('Title: ' || book_title || ', Price: ' ||
book_price);
END LOOP;
CLOSE cr; -- close when work is finished
END;
OUTPUT :
NOTE:
If you are satisfied with my answer please do upvote and if you
have any kind of doubts please post in comment section. i'll surely
help you there.
Thank You:)
Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring...
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...
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...
--- Paper Review drop table paper_review cascade constraint; drop table paper_author cascade constraint; drop table paper cascade constraints; drop table author cascade constraints; drop table reviewer cascade constraints; create table reviewer ( rid int, --- reviewer id rname varchar(50), --- reviewer name remail varchar(50),-- reviewer email raffiliation varchar(50),-- reviewer affiliation primary key (rid) ); insert into reviewer values(1,'Alex Golden', '[email protected]','UMBC'); insert into reviewer values(2,'Ann Stonebraker', '[email protected]','UMD'); insert into reviewer values(3,'Karen Smith', '[email protected]','UMB'); insert into reviewer values(4,'Richard Wallas', '[email protected]','UMBC'); insert into...
Please write ONE SQL statement for each of the following tasks using the below tables. Note that you can only use conditions specified in the task description and cannot manually look up data and add conditions. Task 1: return title of textbooks with price over $100. Task 2: return number of courses sections scheduled for each year and semester. Please return year, semester, and number of courses. Task 3: Return names of all courses in Information Systems undergraduate program. Task...
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 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...
a. Write five select statements to select data from each table individually. b. Write one select statement with joins to list the playlist name, playlist track number, song name, artist name, album name, sorted by playlist name and playlist track number. DROP TABLE Artists CASCADE CONSTRAINTS; DROP TABLE Albums CASCADE CONSTRAINTS; DROP TABLE Songs CASCADE CONSTRAINTS; DROP TABLE Playlists CASCADE CONSTRAINTS; DROP TABLE PlaylistSongs CASCADE CONSTRAINTS; CREATE TABLE Artists ( ArtistID int NOT NULL, ArtistName varchar(255), PRIMARY KEY (ArtistID) );...
Question: Write one SQL statement for the following question: Return number of players whose rating is over 1000. Background information: This is a chess tournament management database that stores information about chess players, tournaments, sections, registrations, and pairings. Each player has an ID, name, grade (0 to 12) and rating. Each tournament has a number of sections. Each player can register for a section of a tournament In each round of a tournament, players in the same section will be...
/* I am executing following SQL statement for the below code but I am getting error. Pls, upload screenshot after running it. SQL Statement: SELECT OfferNo, CourseNo FROM Offering WHERE OfferTerm = 'Sum' AND OfferYear = 2012 AND FacSSN IS NULL; */ CREATE TABLE STUDENT( StdSSN INT NOT NULL PRIMARY KEY, StdFName VARCHAR2(50), StdLName VARCHAR2(50), StdCity VARCHAR2(50), StdState VARCHAR2(2), StdZip VARCHAR2(10), StdMajor VARCHAR2(15), StdYear VARCHAR2(20) ); CREATE TABLE FACULTY( FacSSN INTEGER NOT NULL PRIMARY KEY, FacFName VARCHAR(50), FacLName VARCHAR(50), FacCity...
Here is the P4 university database ---Drop tables --Drop Table FACULTY Cascade Constraints; --Drop Table OFFERING Cascade Constraints; --Drop Table STUDENT Cascade Constraints; --Drop Table COURSE Cascade Constraints; --Drop Table ENROLLMENT Cascade Constraints; Create Table STUDENT( Std_ID NUMBER(3) Constraint Student_STD_ID_FK PRIMARY KEY, Std_FN Varchar2 (9), Std_LN Varchar2 (8) , Std_City Varchar2 (10), Std_State Varchar2 (4), Std_Zip Number (5), Std_Major Varchar2 (6), Std_Class Varchar2 (3), Std_GPA NUMBER (3,2)); ---Insert records into Student Insert Into STUDENT Values( 101, 'Joe', 'Smith','Eau Clare','WI',18121,'IS','FR',3.8); Insert...