Class12 SQL Exercises

July 28, 2017 | Author: Hari Sampathirao | Category: Sql, Databases, Software Design, Scientific Modeling, Computer Programming
Share Embed Donate


Short Description

ckvvlb;l.n;n;l...

Description

SQL Assignment Library System Use the following Schema to perform the given set of assignment. Tables Member Column Name Member_Id Member_Name Acc_Open_Date Max_Books_Allowed Penalty_Amount

Data Type Number(5) Char(25) Date Number(2) Number(7,2)

Description Unique Member ID Name of the Library member Date of membership Total Number of books that can be issued to the member. Penalty amount due

Book Column Name Book_No Book_Name Author Cost Category

Data Type Number(6) VarChar2(30) Char(30) Number(7,2) Char(10)

Description Book identification number Name of the book Author of the book Cost of the book Category like Science,Fiction etc

Issue Column Name Lib_Issue_Id Book_No Member_Id Issue_Date Return_date

Data Type Number(10) Number(6) Number(5) Date Date

Description Library Book Issue No Number of the book issued Member that issued the book Date of Issue 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

1 2

Richa Sharma Garima Sen

Acc_Open _Date 10-Dec-05 Current date

Max_Books_Al lowed 5 3

Penalty_Amoun t 50 Null

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 101 102 103 104

Book Name Let us C Oracle – Complete Ref Mastering SQL PL SQL-Ref

Author Denis Ritchie Loni

Cost 450 550

Category System Database

Loni Scott Urman

250 750

Database 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_ Id 7001 7002 7003 7004 7005 7006

Book No 101 102 104 101 104 101

Member ID 1 2 1 1 2 3

Issue Date

Return Date

10-Dec-06 25-Dec-06 15-Jan-06 04-Jul-06 15-Nov-06 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) 2) 3) 4) 5) 6)

List all the members that became the member in the year 2006. List all the books that are written by Author Loni and has price less then 600. List the Issue details for the books that are not returned yet. Update all the blank return_date with 31-Dec-06 excluding 7005 and 7006. List all the Issue details that have books issued for more then 30 days. 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

--------------------------------

101 102

is written by is written by

NAME Denis Ritchie 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) 5) 6) 7)

Add a constraint Price < 2500 to Book table. View all the constraints for table Issue_C using view User_Constraints. Disable constraint created in step 3-d 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.

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF