top of page

Oracle Database Practice Set | Libraries Relational Database Schema



SQL Queries

a) Use your script from HW Assignment 6 to create the LIBRARY relational database schema in the figure below, in your Oracle schema. (Alternatively, a solution script HW6_SQL_DDL_Library.sql will be provided for that assignment after the submission window closes.)


b) Use the HW7_HW8_SQL_DML_Library.sql script provided on Canvas to populate the LIBRARY tables. If you use your HW Assignment 6 script and get errors because varchar attributes are limited to less characters than used in the insert statements, please extend the allowed size for these attributes, recreate the LIBRARY tables, and run again the script to populate them. Leave the tables in your schema until your assignment is graded in Canvas.


c) Find the names of all authors of books published by "Penguin" that cost more than $10. Make sure each name is included only once in the result.


d) Find the title, publisher and price for all books with an unknown author.


e) The library is setting a summer reading program, where each book values a number of points, based on its length; the formula to determine points for a book is number of pages / 100, rounded up to the nearest integer. Calculate the number of points for each book and list it together with the book id and title. Name the calculated column "no_of_points".


f) Find the title and publisher of all books that are priced between 3 and 6 dollars. Requirements:

- All titles from each publisher must be reported consecutively, and sorted alphabetically from A to Z.

- Publisher names must be all shown in capital letters.

- The report must have the 3 columns: publisher, title, and a new calculated column that should be named "Selling price". A partial result is shown below:

g) How many copies of the book titled "The Lost Tribe" are owned by the library branch whose name is "Newport Branch"? Report the library branch id, name, and number of copies of the book. Separate join conditions from where conditions.


h) Find the card number and name of all members who have borrowed books from the Alexandria library branch. Requirements:

  • List borrowers ordered by their card number.

  • Make sure each name is included only once in the result.

  • Separate join conditions from where conditions.

i) Find the card numbers of all library members who have not borrowed any books from the library. You must use set operations to write this query.


DDL(Data Definition Language)

drop table book_loans;
drop table book_copies;
drop table book;
drop table library_branch;
drop table borrower;

create table library_branch
	(branch_id int,
	branch_name varchar2(20),
	address varchar2(50),
	primary key (branch_id));

create table book
	(book_id int,
	title varchar2(50),
	publisher varchar2(30),
	author varchar2(30),
	price numeric (6,2),
	primary key (book_id));

create table book_copies
	(book_id int,
	branch_id int,
	no_of_copies int,
	primary key (book_id, branch_id),
	foreign key (book_id) references book,
	foreign key (branch_id) references library_branch);

create table borrower
	(card_no int,
	name varchar2(30),
	address varchar2(50),
	phone varchar2(12),
	primary key (card_no));	

create table book_loans
	(book_id int,
	branch_id int,
	card_no int,
	date_out date,
	due_date date,
	primary key (book_id, branch_id, card_no),
	foreign key (book_id, branch_id) references book_copies,
	foreign key (card_no) references borrower);

alter table book add (no_of_pages int);

commit;

-- library_branch

insert into library_branch(branch_id, branch_name, address)
values (1, 'Fort Thomas Branch', '1000 Highland Ave, Fort Thomas, KY 41075');

insert into library_branch(branch_id, branch_name, address)
values (2, 'Fort Thomas Branch', '1000 Highland Ave, Fort Thomas, KY 41075');

insert into library_branch(branch_id, branch_name, address)
values (3, 'Fort Thomas Branch', '1000 Highland Ave, Fort Thomas, KY 41075');

insert into library_branch(branch_id, branch_name, address)
values (4, 'Fort Thomas Branch', '1000 Highland Ave, Fort Thomas, KY 41075');

-- book

insert into book(book_id, title, publisher, author, price, no_of_pages)
values(1,'The Lost Tribe','Penguin','John Smyth',5.50,275);

insert into book(book_id, title, publisher, author, price, no_of_pages)
values(2,'How to Sew Buttons','Kensington','Jane Do',4.35,50);

insert into book(book_id, title, publisher, author, price, no_of_pages)
values(3,'The Terrible Night','Penguin','John Smyth',7.89,280);

insert into book(book_id, title, publisher, author, price, no_of_pages)
values(4,'Mindy''s Mittens','Scholastic','Eleanor Mellors',5.50,35);

insert into book(book_id, title, publisher, author, price, no_of_pages)
values(5,'Pizza and Donuts Diet','Kensington','Jane Do',10.5,80);

-- book_copies

INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(1,2,2);
INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(1,1,3);
INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(2,2,2);
INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(3,3,2);
INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(4,4,2);
INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(5,1,5);
INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(6,2,2);
INSERT INTO book_copies (book_id,branch_id,no_of_copies) VALUES(7,3,1);

-- borrower

INSERT INTO Borrower(card_no,name,address,phone) values(1,'Charlie Brown','27 Main St, Newport','859-555-5123');
INSERT INTO Borrower(card_no,name,address,phone) values(2,'Rachel Rigby','101 Hwy 22, Cold Spring','859-688-7711');
INSERT INTO Borrower(card_no,name,address,phone) values(3,'Nancy Drew','5678 Oak St, Newport','859-555-3467');
INSERT INTO Borrower(card_no,name,address,phone) values(4,'Derek Jones','6789 Ritmo Cir, Cold Spring','859-222-1234');
INSERT INTO Borrower(card_no,name,address,phone) values(5,'Howie Han','111 First Ave, Anderson','513-234-5678');
INSERT INTO Borrower(card_no,name,address,phone) values(6,'Tim Tegulpas','432 Nebraska Ave, Alexandria','859-987-6543');
INSERT INTO Borrower(card_no,name,address,phone) values(7,'Sam Semel','7688 Hedge Ct, Wilder','859-777-9898');
INSERT INTO Borrower(card_no,name,address,phone) values(8,'Evan Mann','4545 Court St, Alexandria','859-899-9090');
INSERT INTO Borrower(card_no,name,address,phone) values(9,'Sally Short','323 Remington St, Alexandria','859-767-8991');
INSERT INTO Borrower(card_no,name,address,phone) values(10,'Bob Biggs','227 South St, Ft. Thomas',null);

--book_loans

INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(1,1,4,to_date('2020-08-20', 'yyyy-mm-dd'),to_date('2020-09-20', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(2,2,4,to_date('2020-08-20', 'yyyy-mm-dd'),to_date('2020-09-20', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(3,3,4,to_date('2020-08-20', 'yyyy-mm-dd'),to_date('2020-09-20', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(4,4,4,to_date('2020-08-19', 'yyyy-mm-dd'),to_date('2020-09-19', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(5,1,4,to_date('2020-08-19', 'yyyy-mm-dd'),to_date('2020-09-19', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(6,2,2,to_date('2020-09-19', 'yyyy-mm-dd'),to_date('2020-10-19', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(7,3,2,to_date('2020-09-19', 'yyyy-mm-dd'),to_date('2020-10-19', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(8,4,2,to_date('2020-09-18', 'yyyy-mm-dd'),to_date('2020-10-18', 'yyyy-mm-dd'));
INSERT INTO book_loans(book_id,branch_id,card_no,date_out,due_date) VALUES(9,1,2,to_date('2020-09-18', 'yyyy-mm-dd'),to_date('2020-10-18', 'yyyy-mm-dd'));
commit;

Solution

Requirements a) and b): Leave the LIBRARY tables in your schema until your assignment is graded in Canvas.


Query c): select author

from book

where publisher='Penguin' AND price>10;


output:


Query d):

select TITLE,PUBLISHER,PRICE from book where AUTHOR='unknown';


Query e):

Select book_id, title, (no_of_pages/100) as no_of_points from book;


Query f):

Select Upper(publisher), title,'Selling_price' || ' ' ||'$' || price as Selling_price from book where price between 3 and 6;


Query g):

select book_copies.branch_id, book.title, book_copies.no_of_copies from book

inner join book_copies on book.book_id = book_copies.book_id

inner join library_branch on library_branch.branch_id = book_copies.branch_id where library_branch.branch_name = 'Newport Branch' and book.title = 'The Lost Tribe';


Query h):

select Borrower.card_no, Borrower.name

from Borrower

inner join book_loans on book_loans.card_no = borrower.card_no

inner join book_copies on book_copies.book_id = book_loans.book_id and book_copies.branch_id = book_loans. branch_id

inner join library_branch on library_branch.branch_id = book_copies.branch_id

where library_branch.branch_name='Alexandria';


Query i):

select card_no from Borrower

minus

select Borrower.card_no

from Borrower

inner join book_loans on book_loans.card_no = borrower.card_no

inner join book_copies on book_copies.book_id = book_loans.book_id and book_copies.branch_id = book_loans. branch_id

inner join library_branch on library_branch.branch_id = book_copies.branch_id

where library_branch.branch_name='Alexandria';



Send Your Requirement Details at:

realcode4you@gmail.com

To get help in any other databases.


134 Comments


Jddj Jx
Jddj Jx
6 hours ago

Trong lúc theo dõi các cuộc thảo luận của cộng đồng, mình thấy sv 888 được nhắc đến trong một vài bình luận nên cũng tò mò mở vào tham khảo. Mình chủ yếu xem nhanh giao diện và cách tổ chức các mục nội dung để nắm sơ bộ về trang. Điều mình chú ý là các chuyên mục được bố trí khá hợp lý, giúp việc theo dõi thông tin trở nên thuận tiện hơn. Xem xong một lượt rồi mình tiếp tục đọc những chủ đề khác mà mình đang quan tâm.

Like

hi c
hi c
18 hours ago

Trong lúc lướt qua mấy chủ đề thảo luận trên các diễn đàn, mình thấy nhiều người nhắc tới tài xỉu md5 nên cũng tò mò bấm vào xem thử cho biết. Mặc dù chỉ mới lướt qua một vòng tổng thể chứ chưa trải nghiệm sâu từng mục, nhưng ấn tượng ban đầu của mình là giao diện được làm khá chỉn chu, không gian trình bày thoáng đãng và bố cục được phân chia rất hợp lý nên nhìn vào cảm thấy vô cùng dễ chịu.

Like

Bé Cô
Bé Cô
2 days ago

Trong lúc lướt qua các cuộc trao đổi của cộng đồng, mình thấy 789win com được đề cập trong một số bình luận nên cũng tò mò mở vào tham khảo. Mình chủ yếu quan sát cách tổ chức nội dung và giao diện tổng thể để có cái nhìn ban đầu. Theo cảm nhận của mình, các chuyên mục được bố trí khá hợp lý, giúp việc theo dõi thông tin trở nên thuận tiện hơn. Xem qua một lúc rồi mình tiếp tục với những bài viết khác mà mình đang quan tâm.

Like

sensing patrina
sensing patrina
3 days ago

S8. com Trong lúc tìm hiểu một chủ đề mình đang quan tâm, mình thấy website này được một số người nhắc đến nên quyết định vào trải nghiệm. Mình không đọc hết toàn bộ nội dung mà chỉ xem tổng quan cách website được thiết kế và bố trí thông tin. Theo cảm nhận của mình, các chuyên mục được sắp xếp khá hợp lý, giao diện nhìn rõ ràng nên việc theo dõi tương đối dễ dàng. Trong quá trình sử dụng, website phản hồi nhanh, thao tác chuyển giữa các trang mượt và hiển thị tốt trên điện thoại. Nhìn chung, đây là một website được đầu tư khá cẩn thận và mang lại trải nghiệm sử…

Like

S8. com Mình vô tình biết đến website này khi đang tìm kiếm một vài thông tin trên mạng nên cũng ghé vào xem thử. Mình không dành nhiều thời gian đọc chi tiết từng phần, chủ yếu muốn xem cách họ bố trí giao diện và sắp xếp các chuyên mục có thuận tiện không. Cảm nhận đầu tiên là tổng thể được trình bày khá ngăn nắp, các khu vực nội dung được phân chia rõ ràng nên khi lướt qua vẫn dễ nắm được cấu trúc của trang. Mình cũng thấy các chuyên mục chính hiển thị khá trực quan, việc chuyển giữa các phần diễn ra nhanh và không cần phải tìm kiếm quá nhiều. Nhìn chung,…

Like

REALCODE4YOU

Realcode4you is the one of the best website where you can get all computer science and mathematics related help, we are offering python project help, java project help, Machine learning project help, and other programming language help i.e., C, C++, Data Structure, PHP, ReactJs, NodeJs, React Native and also providing all databases related help.

Hire Us to get Instant help from realcode4you expert with an affordable price.

USEFUL LINKS

Discount

ADDRESS

Noida, Sector 63, India 201301

Follows Us!

  • Facebook
  • Twitter
  • Instagram
  • LinkedIn

OUR CLIENTS BELONGS TO

  • india
  • australia
  • canada
  • hong-kong
  • ireland
  • jordan
  • malaysia
  • new-zealand
  • oman
  • qatar
  • saudi-arabia
  • singapore
  • south-africa
  • uae
  • uk
  • usa

© 2023 IT Services provided by Realcode4you.com

bottom of page