Question

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 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');

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');

--- 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);

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 some HCC courses

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);

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);

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);

commit;

Task 1: Return names of all courses in Information Systems undergraduate program Task 2: Return titles and prices of textbook

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

--query 1

select cname from course c where pid IN (select pid from program where lower(pname) = 'information systems');
-- since there are multiple information system program so IN is used.

--query 2
select title, price from textbook where tbid IN (select tbid from textbook_schedule where sid IN (select sid from schedule where semester = 'spring' AND year = 2019 AND snumber = 1 AND cid =
(select cid from course where cname LIKE 'IS 420%')));

-- query 4
select cname from course where cid = (select cid from schedule where year = 2019 AND semester = 'spring'
group by cid, snumber having count(snumber) >= 2);

--query 5
select a.aname from textbook_author t natural JOIN author a where t.tbid IN
(select tbid from textbook_author where aid = (select aid from author where aname = 'Jeff Hoffer'));

-- query 6

UPDATE textbook SET quantity = quantity + 10 WHERE tbid IN (SELECT tbid FROM textbook_schedule
WHERE sid IN (SELECT sid FROM schedule where year = 2019 AND semester = 'spring' AND cid = (
SELECT cid From course where cname like 'IS 420%')))

Add a comment
Know the answer?
Add Answer to:
Use the SQL statements provided to create your tables. Write one SQL statement for each of...
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
  • Suppose a student is taking IS 620 section 1 and HCC 629 section 1 for spring...

    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;...

  • 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...

  • Please write ONE SQL statement for each of the following tasks using the below tables. Note...

    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...

  • --- Paper Review drop table paper_review cascade constraint; drop table paper_author cascade constraint; drop table paper...

    --- 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...

  • Question: Write one SQL statement for the following question: Return number of players whose rating is...

    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...

  • a. Write five select statements to select data from each table individually. b. Write one select...

    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) );...

  • (SQL) Write DDL statements to create the tables below and use appropriate data types for the...

    (SQL) Write DDL statements to create the tables below and use appropriate data types for the attributes.Relational database schema: Teacher = [CourseN, Quarter,TeacherName] Course = [CourseN,CourseName, Nunit) LocationNTime = [CourseN, Quarter , DayTime, RoomN] . //Examples of DayTime: M2:00AM, W4:50PM, and T8:00PM. Note that DayTime is represented as a string. Student = [studentName, CourseN, Quarter] .................... The DDL statement must include at least the following constraints: Every Primary Key; Every Foreign Key; For every Foreign Key constraint, the referential integrity...

  • 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...

  • Use an INSERT INTO statement with a subquery containing a SQL string function to create user...

    Use an INSERT INTO statement with a subquery containing a SQL string function to create user names for the volunteers based on their legal names and insert them into the table. +----------------------+ | Tables_in_volunteers | +----------------------+ | address              | | email                | | funds                | | hours                | | person               | | phone                | | users                | +----------------------+ users legal names are in the address table user table is : CREATE TABLE USERS(volunteer_id INT NOT NULL, username VARCHAR(50), PRIMARY KEY...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

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