PDF Class12 SQL Exercises
PDF Class12 SQL Exercises
Library System
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
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.
Insert at least 5 records with suitable data, put null values in various columns
other then member id and name in different records.
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.
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 :
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
functions.
Set Operators , Joins ,Subquery: Inline, Correlated, complex queries.
Task / Problems:
Day # 4 Assignments
Task / Problems: