0% found this document useful (1 vote)
1K views7 pages

PDF Class12 SQL Exercises

This document provides the schema and tasks for a SQL assignment on a library management system. The schema includes tables for Members, Books, and Book Issues. The tasks involve creating, modifying and inserting data into the tables, as well as queries to retrieve data using functions, operators, joins and aggregates. Over three days, participants will learn skills including DDL, DML, transactions, select queries, functions, sorting, grouping and advanced concepts like subqueries and joins.

Uploaded by

Ashwini Patil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (1 vote)
1K views7 pages

PDF Class12 SQL Exercises

This document provides the schema and tasks for a SQL assignment on a library management system. The schema includes tables for Members, Books, and Book Issues. The tasks involve creating, modifying and inserting data into the tables, as well as queries to retrieve data using functions, operators, joins and aggregates. Over three days, participants will learn skills including DDL, DML, transactions, select queries, functions, sorting, grouping and advanced concepts like subqueries and joins.

Uploaded by

Ashwini Patil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 7

SQL Assignment

Library System

Use the following Schema to perform the given set of assignment.

Tables

Member
Column Name Data Type Description
Member_Id Number(5) Unique Member ID
Member_Name Char(25) Name of the Library member
Acc_Open_Date Date Date of membership
Max_Books_Allowed Number(2) Total Number of books that can
be issued to the member.
Penalty_Amount Number(7,2) Penalty amount due

Book
Column Name Data Type Description
Book_No Number(6) Book identification number
Book_Name VarChar2(30) Name of the book
Author Char(30) Author of the book
Cost Number(7,2) Cost of the book
Category Char(10) Category like Science,Fiction
etc

Issue
Column Name Data Type Description
Lib_Issue_Id Number(10) Library Book Issue No
Book_No Number(6) Number of the book issued
Member_Id Number(5) Member that issued the book
Issue_Date Date Date of Issue
Return_date Date Return date
Day # 1 Assignments

Concept: SQL Basics,


DDL commands Create , Alter , Drop
DML commands Insert, Update , Delete ,
Transaction Control Commit , Rollback and Savepoint.

Objective: At the end of the assignments, participants will understand basic such
as DDL/DML/Transaction Control statements.

Task / Problems:

1) Create the table Member, Book and Issue without any constraints as
mentioned in the schema description above.
2) View the structure of the tables.
3) Add column Comments to table Issue of width 100 characters.
4) Modify the table Member increase the width of the member name to
30 characters.
5) Add a column Reference Char(30) to Issue table.
6) Delete/Drop the column Reference from Issue.
7) Rename the table Issue to Lib_Issue.
8) Insert following data in table Member.

Member ID Member Name Acc_Open Max_Books_Al Penalty_Amoun


_Date lowed t
1 Richa Sharma 10-Dec-05 5 50
2 Garima Sen Current 3 Null
date

Insert at least 5 records with suitable data, put null values in various columns
other then member id and name in different records.

9) Modify the column Member Decrease the width of the member


name to 20 characters. (If it does not allow state the reason for that)
10) Try to insert a record with Max_Books_Allowed = 110, Observe the error that
comes. Report the reason for this error.
11) Generate another table Member101 using a Create command along with a
simple SQL query on member table. (Hint : create table x_tbl as select *
from a_tbl;)
12) Insert data in Book table as follows:

Book_No Book Name Author Cost Category


101 Let us C Denis Ritchie 450 System
102 Oracle – Complete Loni 550 Database
Ref
103 Mastering SQL Loni 250 Database
104 PL SQL-Ref Scott Urman 750 Database

13) Insert more records in Book table using & operator in the insert statement.
14) Create table Book101 similar to Book in structure with no data in it.
15) Insert into Book101 all the data in Book table using Select statement.
16) Save all the data so far inserted in the tables.
17) View the data in the tables using simple SQL query.
18) Insert into Book following data.
105, National Geographic, Adis Scott, 1000, Science
19) Undo the last changes.
20) Modify the price of book with id 103 to Rs 300 and category to RDBMS.
21) Rename the table Lib_Issue to Issue.
22) Insert following data into Issue table. Note leave the column
Return_Date blank.

Lib_Issue_ Book No Member Issue Date Return Date


Id ID
7001 101 1 10-Dec-06
7002 102 2 25-Dec-06
7003 104 1 15-Jan-06
7004 101 1 04-Jul-06
7005 104 2 15-Nov-06
7006 101 3 18-Feb-06

23) Save the data.


24) Insert 2 records in Issue table.
25) Modify the Return_Date of 7004,7005 to 15 days after the Issue_date.
26) Modify the Penalty_Amount for Garima Sen to Rs 100.
27) Perform a save point X here.
28) Remove all the records from Issue table where member_ID is
1 and Issue date in before 10-Dec-06.
29) Remove all the records from Book table with category other
then RDBMS and Database.
30) Undo the changes done after savepoint X.
31) Save all the changes done before X.
32) Remove the table Member101.
33) Remove the table Book101.
34) View the data and structure of all the three tables Member, Issue, Book.
35) List all the tables created by the user.
Day # 2 Assignments

Concept: Select Command


SQL operators and functions
Single Row functions: Date, Numeric, Character functions.
Aggregate functions.

Objective: At the end of the assignments, participants will be confident to


understand basic select query, Logical, Arithmetic operators, Date,
character and Numeric function. Aggregate functions and their
use.

Task / Problems:

1) List all the members that became the member in the year 2006.
2) List all the books that are written by Author Loni and has price less then 600.
3) List the Issue details for the books that are not returned yet.
4) Update all the blank return_date with 31-Dec-06 excluding 7005 and 7006.
5) List all the Issue details that have books issued for more then 30 days.
6) List all the books that have price in range of 500 to 750 and has category
as Database.
7) List all the books that belong to any one of the following categories
Science, Database, Fiction, Management.
8) List all the members in the descending order of Penalty due on them.
9) List all the books in ascending order of category and descending order of price.
10) List all the books that contain word SQL in the name of the book.
11) List all the members whose name starts with R or G and contains letter I in it.
12) List the entire book name in Init cap and author in upper case in
the descending order of the book name.
13) Show the data in the following format :

Book No -------------------------------- NAME

101 is written by Denis Ritchie


102 is written by Loni

14) List the Issue Details for all the books issue by member 101 with
Issue_date and Return Date in following format. ‘Monday, July, 10,
2006’.
15) List the data in the book table with category data displayed as
D for Database, S for Science, R for RDBMS and O for all the others.
16) Display the book name, Author name with spaces padded with *.
17) List the Lib_Issue_Id, Issue_Date, Return_Date and No of days Book
was issued.
18) Find the details of the member of the Library in the order of their joining
the library.
19) Display the count of total no of books issued to Member 101.
20) Display the total penalty due for all the members.
21) Find the total cost of all the books that come under category Database.
22) Find the cheapest book price in the library.
23) Find the date on which the very first book was issued in the library.
24) Find the date on which most recent the book was issued.
25) Find the average price of book in Database category.

Day # 3 Assignments

Concept: Group by, Having, Use of Aggregate

functions.
Set Operators , Joins ,Subquery: Inline, Correlated, complex queries.

Objective: At the end of the assignments, participants will be confident to


understand the various concepts related to extracting data from
multiple tables, relationship, Set operators and complex queries.

Task / Problems:

1) List the various categories and count of books in each category.


2) List the book_No and the number of times the book is issued in the
descending order of count.
3) Find the maximum, minimum, total and average penalty amount in the
member table.
4) Display the member id and the no of books for each member that has
issued more then 2 books.
5) Display the member id, book no and no of times the same book is issued by
the member in the descending order of count.
6) Display the month and no of books issued each month in the descending
order of count.
7) List the book_no of all the books that are not issued to any member so far.
8) List all the member id that exist in member table and has also at least one
book issued by them.
9) List the member ID with highest and lowest no of books issued.
10) List all the Issue_details for books issued in December and July without
using any arithmetic, Logical or comparison operator.
11) List the Book_No, Book_Name and Issue_date for all the books that are
issued in month of December and belong to category Database.
12) List the Member Id, Member Name and No of books Issued in the
descending order of the count.
13) List the Book No, Book Name, Issue_date and Return_Date for all the
books issued by Richa Sharma.
14) List the details of all the members that have issued books in Database category.
15) List all the books that have highest price in their own category.
16) List all the Issue_Details where Issue_date is not within the Acc_open_date
and Return_date for that member.
17) List all the members that have not issued a single book so far.
18) List all the Members where No of books Issued exceeds the Max No of
books allowed.
19) List all the members that have issued the same book as issued by Garima.
20) List the Book_Name, Price of all the books that are not returned for more
then 30 days.
21) List all the authors and book_name that has more then 1 book written by them.
22) List the Member ID, Member Name of the people that have issued the
highest and the lowest no of books.
23) List the details of highest 3 priced books.
24) List the total cost of all the books that are currently issued but not returned.
25) List the details of the book that has been issued maximum no of times.

Day # 4 Assignments

Concept: Constraints Views Index

Objective: At the end of the assignments, participants will be confident


to understand the various concepts related to Constraints, Views and
Indexes.

Task / Problems:

1) Create table Member_C with following constraints.


a. Member_Id – Primary Key
b. Acc_Open_Date – Default System date.
c. Max_Allowed_Books < 100
d. Penalty maximum 1000.

2) Create table Book_C with following constraints.


a. Book_No – Primary Key
b. Book_Name – Not Null
c. Category – Science, Fiction, Database, RDBMS, Others.

3) Create table Issue_C with following constraints.


a. Lib_Issue_Id – Primary Key
b. Member_Id – Foreign Key
c. Book_No – Foreign key
d. Issue_date < Return_date

4) Add a constraint Price < 2500 to Book table.


5) View all the constraints for table Issue_C using view User_Constraints.
6) Disable constraint created in step 3-d
7) Create a Read Only view to display Lib_Issue_Id, Book_Name, Member_Name,
Author and Issue_date for all the books that have price between 500 – 750
and category as Database or RDBMS.
8) Create a view with check option to display all the books that has price greater
then 500.
9) Perform DML operations to the view and evaluate the effect of Check Option.
10) Create Index on Book_Name in book table.
11) Create Index on Member_Id, Book_No in Issue table.
12) State difference between Index vs Unique Index.
13) Do we need to create index on Member_Id in Member_C table if not, state
the reason for the same.

You might also like