Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

I'm having trouble with this please help, thanks in advance. ASSIGNMENT: Develop a SQL query that will select all of the books that are currently

I'm having trouble with this please help, thanks in advance.

ASSIGNMENT:

Develop a SQL query that will select all of the books that are currently checked out and are past due to be returned, which have a value greater than $10.00. Your query must return the name, address, postal code, and phone number of the borrower, the name and phone number of the librarian responsible for the transaction, the date the book was due to be returned, and the name, cost, and ISBN number of the book. You query should sort the list by the return date in descending order.

MY CURRENT TABLES:

create table book (

title varchar(60) not null,

author varchar(40),

cost decimal(10,2),

isbn_number integer not null

);

alter table book add unique (isbn_number);

alter table book add primary key (isbn_number);

create table bookcopy (

Isbn_number integer,

publicationdate date,

sequence integer);

alter table bookcopy add primary key (isbn_number,

sequence);

alter table bookcopy add CONSTRAINT bookcopy_uniq U

NIQUE (ISBN_number, sequence);

alter table bookcopy add CONSTRAINT book_fkey FOREI

GN KEY (isbn_number) REFERENCES book (isbn_number)

ON DELETE CASCADE;

create table borrower (

librarycard integer,

name char(40),

address char(40),

postalcode char(20),

phonenumber char(20),

membershipdate date);

alter table borrower add primary key (librarycard);

create table librarian (

librarianid integer,

name char(40),

phonenumber char(20),

supervisor integer);

alter table librarian add primary key (librarianid)

;

create table booklended (

librarycard integer not null,

checkoutdate date not null,

returndate date,

ISBN_number integer not null,

sequence integer not null,

librarianid integer not null

);

alter table booklended add PRIMARY KEY (ISBN_number

, sequence, librarycard, checkoutdate);

alter table booklended add CONSTRAINT booklended_un

iq UNIQUE (ISBN_number, sequence, librarycard,

checkoutdate);

alter table booklended add CONSTRAINT borrower_fkey

FOREIGN KEY (librarycard) REFERENCES borrower

(librarycard) ON DELETE CASCADE;

alter table booklended add CONSTRAINT librarian_fkey

FOREIGN KEY (librarianid) REFERENCES librarian

(librarianid) ON DELETE CASCADE;

alter table booklended add CONSTRAINT bookcopy_fkey

FOREIGN KEY (isbn_number, sequence) REFERENCES

bookcopy (isbn_number, sequence);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions