SQL3
SQL3
SQL3
Database: Library
Create Following tables and insert tuples with suitable constraints
Table: Books
Table : Issued
Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
T0002 5
F0002 8
Create table :-
Table 1:-
SQL> create table books (book_id varchar(10), book_name varchar(15), author_name varchar(15),
publishers varchar(10),price number, type varchar(10), quantity number, primary key(book_id));
Table created.
Priya M R 17
DBMS Lab Manual
Table 2:-
SQL> create table issued(book_id varchar(10), Qty_issued number, foreign key(book_id) references
books(book_id));
Table created.
Table 1:-
1 row created.
SQL> /
Enter value for book_id: F0001
Enter value for book_name: The Tears
Enter value for author_name: William Hopkins
Enter value for publishers: First Publ
Enter value for price: 650
Enter value for type: Fiction
Enter value for quantity: 20
1 row created.
SQL> /
Enter value for book_id: T0001
Enter value for book_name: My First C++
Enter value for author_name: Brain & Brooke
Enter value for publishers: ERP
Enter value for price: 350
Enter value for type: Text
Enter value for quantity: 10
1 row created.
SQL> /
Enter value for book_id: T0002
Enter value for book_name: C++ Brainworks
Enter value for author_name: A.W.Rossaine
Enter value for publishers: TDH
Enter value for price: 350
Enter value for type: Text
Enter value for quantity: 15
1 row created.
Priya M R 18
DBMS Lab Manual
SQL> /
Enter value for book_id: F0002
Enter value for book_name: Thunderbolts
Enter value for author_name: Ana Roberts
Enter value for publishers: First Publ
Enter value for price: 750
Enter value for type: Fiction
Enter value for quantity: 50
1 row created.
Table 2:-
1 row created.
SQL> /
Enter value for book_id: C0001
Enter value for qty_issued: 5
1 row created.
SQL> /
Enter value for book_id: F0001
Enter value for qty_issued: 2
1 row created.
SQL> /
Enter value for book_id: T0002
Enter value for qty_issued: 5
1 row created.
SQL> /
Enter value for book_id: F0002
Enter value for qty_issued: 8
1 row created.
Priya M R 19
DBMS Lab Manual
BOOK_ID QTY_ISSUED
---------- ----------
T0001 4
C0001 5
F0001 2
T0002 5
F0002 8
Queries:-
1. To show Book name, Author name and price of books of First Publ. publisher
2. Display Book id, Book name and publisher of books having quantity more than 8 and price
less than 500.
3. Select Book id, book name, author name of books which is published by other than ERP
publishers and price between 300 to 700.
Priya M R 20
DBMS Lab Manual
4. Generate a Bill with Book_id, Book_name, Publisher, Price, Quantity, 4% of VAT “Total”.
5. Display book details with book id‟s C0001, F0001, T0002, F0002 (Hint: use IN operator)
BOOK_NAME
---------------
My First C++
C++ Brainworks
7. Display book details with author name starts with letter „A‟.
8. Display book details with author name starts with letter „T‟ and ends with „S‟.
no rows selected
Priya M R 21
DBMS Lab Manual
10. List the book_name, Author_name, Price. In ascending order of Book_name and then on
descending order of price.
SQL> select book_name,author_name,price from books order by book_name asc, price desc;
Priya M R 22