Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write at least 8 queries on your database, using the select-from-where construct of SQL. All of your queries should exhibit interesting features of SQL: queries

Write at least 8 queries on your database, using the select-from-where construct of SQL. All of your queries should exhibit “interesting” features of SQL: queries over more than one relation, sub-queries (you may have at most one query involving a single relation, at least one that involves two relations and at least one that involves three relations), grouping and aggregation.

create table Student(
Student_ID int primary key,
FName varchar(45),
LName varchar(45),
Contact_Num char(20),
Email varchar(45),
Borrow_ID int,
UNIQUE (Borrow_ID)
);

create table Books(
ISBN int primary key,
Book_Title varchar(45),
Book_Edition int,
Publication_Year int,
Language varchar(45),
UNIQUE (Book_Title)
);

create table Branch(
Branch_ID int primary key,
Branch_Name varchar(45),
B_Location varchar(45),
B_Email varchar(45),
B_ContactNum char(20)
);

create table Author(
FName varchar(10) primary key,
LName varchar(45),
Book_Title varchar(45),
Book_Date date,
foreign key (Book_Title) references Books(Book_Title)
);

create table Staff(
Staff_ID int primary key,
FName varchar(45),
LName varchar(45),
S_Num char(20),
Branch_ID int,
foreign key (Branch_ID) references Branch(Branch_ID)
);

create table Borrow_Book(
Borrower_ID int primary key,
Book_ID int,
Borrowed_From_Date date,
Borrowed_To_Date date,
Issued_ID int,
foreign key (Borrower_ID) references Student(Borrow_ID),
foreign key (Book_ID) references Books(ISBN),
foreign key (Issued_ID) references Staff(Staff_ID),
unique(Book_ID)
);

create table Issued_Books(
Issued_ID int primary key,
Book_Title varchar(45),
Book_ID int,
Date_Issued date,
foreign key (Book_Title) references Books(Book_Title),
foreign key (Book_ID) references Books(ISBN),
foreign key (Issued_ID) references Staff(Staff_ID),
UNIQUE(Book_Title),
unique(Book_ID)
);

create table Copies_of_Books(
Book_ID int primary key,
Book_Title varchar(45),
Num_Of_Copies_Actual int,
Num_Of_Copies_Current int,
foreign key (Book_Title) references Books(Book_Title),
foreign key (Book_ID) references Books(ISBN)
);

create table Return_Books(
Book_ID int primary key,
Book_Title varchar(45),
Borrower_ID int,
Borrowed_To_Date date,
Actual_Return_Date date,
foreign key (Book_ID) references Issued_Books(Book_ID),
foreign key (Book_Title) references Issued_Books(Book_Title),
foreign key (Borrower_ID) references Borrow_Book(Borrower_ID)
);

create table untarnished_Books(
Book_ID int primary key,
Book_Title varchar(45),
Issued_ID int,
Condition_out_of_ten int default'0',
foreign key (Book_ID) references Issued_Books(Book_ID),
foreign key (Book_Title) references Issued_Books(Book_Title),
foreign key (Issued_ID) references Issued_Books(Issued_ID)
)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Eight SQL queries that exhibit various features such as joins subqueries grouping and aggregation using the provided database schema Query 1 Find the ... blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Programming With Microsoft Visual Basic 2017

Authors: Diane Zak

8th Edition

1337102121, 9781337517058, 978-1337102124

More Books

Students also viewed these Databases questions