0% found this document useful (0 votes)
6 views11 pages

Pcc-cs591 Lab Assignment

Uploaded by

Jaipuria College
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Pcc-cs591 Lab Assignment

Uploaded by

Jaipuria College
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Brainware University

Department of Computer Science and Engineering


B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 1
1. Create the following tables with appropriate constraints using SQL command.
Example:
SQL Query for creating table
CREATE TABLE <TABLE NAME>
(<COLUMN NAME 1> <DATA TYPE>,
<COLUMN NAME 2> <DATA TYPE> NOT NULL1 ,
………………………………………………………………………);
1
If Attribute is NOT NULL.

SQL Query to add constraints


ALTER TABLE <TABLE NAME> ADD CONSTRAINT <CONSTRAINT NAME> PRIMARY KEY
(<COLUMN NAME>);

ALTER TABLE <TABLE NAME> ADD CONSTRAINT <CONSTRAINT NAME> CHECK


<COLUMN NAME> IN (VALUE1, VALUE2,………);

ALTER TABLE <TABLE NAME> ADD CONSTRAINT <CONSTRAINT NAME> FOREIGN KEY
<COLUMN NAME> REFERENCES <TABLE NAME> <COLUMN NAME>;

A) Table Name : Member

COLUMN NAME DATA TYPE DESCRIPTION


Member_Id Number(5) Unique Member ID
Member_Name Varchar2(30) Name of the Library member
Member_address Varchar2(50) Address of the member
Acc_Open_Date Date Date of membership
Membership_type Varchar2(20) Type of the membership such as ‘Lifetime’,’
Annual’, ‘Half Yearly’,’ Quarterly’
Fees_paid Number(4) Membership fees paid
Max_Books_Allowed Number(2) Total Number of books that can be issued to the
member.
Penalty_Amount Number(7,2) Penalty amount due

CONSTRAINT:
a. Member_Id – Primary Key
b. Member_Name – NOT NULL
c. Membership_type - ‘Lifetime’,’ Annual’, ‘Half Yearly’,’ Quarterly’
d. Max_books_allowed <7
e. Penalty_amt maximum 1000

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

B) Table Name : BOOKS

COLUMN NAME DATA TYPE DESCRIPTION


Book_No Number(6) Book identification number
Book_Name VarChar2(30) Name of the book
Author_name Varchar2(30) Author of the book
Cost Number(7,2) Cost of the book
Category Char(10) Category like Science , Fiction etc.

CONSTRAINT:
a. Book_No – Primary Key
b. Book_Name – Not Null
c. Category – Science, Database, System, Others.

C) Table Name : ISSUE

COLUMN NAME DATA TYPE DESCRIPTION


Lib_Issue_Id Number(10) Library Book Issue No
Book_No Number(6) The ID of book, which is issued
Member_Id Number(5) Member that issued the book
Issue_Date Date Date of Issue
Return_date Date Return date

CONSTRAINT:

a. Lib_Issue_Id -Primary key


b. Book_No - foreign key
c. Member_id - foreign key

2. Insert the following data to the appropriate table using SQL command.
Example:
SQL Query for inserting data into table

INSERT INTO <TABLE NAME> (COLUMN1, COLUMN2, COLUMN3, ……………) VALUES


(DATA1, DATA2, DATA3, ………………..);
OR
INSERT INTO <TABLE NAME> VALUES (DATA1, DATA2, DATA3, ………………..);
OR
INSERT INTO <TABLE NAME> VALUES (&COLUMN1, &COLUMN2, &COLUMN3, …………);

N.B Generally first form is the main query to insert data into the table. But normally we use the second one. First
one is used if data are not present for every attribute. Finally third one used to insert the user define data to the
Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)
table. Last one do not run in to the oracle express edition. For every case data values must be written serially
according to the column name. If data value is character type, it writes with in single inverted comma (‘char ‘).

A) Table Name : Member

MEMB MEMBER_NA MEMBER_A ACC_OPEN MEMBERSHI FEES_P MAX_BOOKS_ PENALTY_


ER_ID ME DDRESS _DATE P_TYPE AID ALLOWED AMOUNT
1 Sayantan Sinha Pune 10-Dec-10 Lifetime 2000 6 50
2 Abhirup Sarkar Kolkata 19-jan-11 Annual 1400 3 0
3 Ritesh Bhuniya Gujarat 20-feb-11 Quarterly 350 2 100
4 Paresh sen Tripura 21-mar-11 Half yearly 700 1 200
5 Sohini Haldar Birbhum 11-apr-11 Lifetime 2000 6 10
6 Suparna Biswas Kolkata 12-apr-11 Half Yearly 700 1 0
7 Suranjana Basu Purulia 30-june-11 Annual 1400 3 50
8 Arpita Roy Kolkata 31-july-11 Half yearly 700 1 0

B) Table Name : BOOKS

BOOK_NO BOOK_NAME AUTHOR_NAME COST CATEGORY


101 Let us C Denis Ritchie 450 Others
102 Oracle – Complete Ref Loni 550 Database
103 Visual Basic 10 BPB 700 Others
104 Mastering SQL Loni 450 Database
105 PL SQL-Ref Scott Urman 750 Database
106 UNIX Sumitava Das 300 System
107 Optics Ghatak 600 Science
108 Data Structure G.S. Baluja 350 Others

C) Table Name : ISSUE


LIB_ISSUE_ID BOOK_NO MEMBER_ID ISSUE_DATE RETURN_DATE
7001 101 1 10-jan-11
7002 102 2 25-jan-11
7003 104 1 1-Feb-11
7004 104 2 15-Mar-11
7005 101 4 04-Apr-11
7006 108 5 12-apr-11
7007 101 8 1-Aug-11

SQL Query to retrieve data of table.


SELECT * FROM <TABLE NAME>; (Use to see the whole data of table)
SELECT COLUMN NAME1, COLUMN NAME2, ………… FROM <TABLE NAME>;
(Use to see the data of the particular attributes of the table)

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 2
1. Retrieve the Name of Book and Cost who has Maximum cost.
2. Calculate the Minimum cost, Average cost and Total cost value in BOOKS table and Rename the
resulting attributes.
3. Retrieve the Name and ID of Members who’s issued book between 26th January 2011 and 14th
April 2011.
4. Retrieve Book Name, Author Name and Category whose Category is not ‘OTHERS’.
5. Retrieve the Book name and Author Name where 5th letter of the Author name is ’t’.
6. How many Books are available whose Cost is greater than 350.
7. How many different Authors name are available in BOOKS table.
8. Calculate the following Numeric functions:
a. What is the absolute value of -167.
b. Calculate 8^6.
c. Round up to 2 decimal points (134.56789).
d. What is the square root of 144
e. Floor and Ceil value of 13.15.
9. Extract Year, Month, Day from System Date.
10. What is the greatest value between 4, 5 and 17.
11. What is the Least value between '4', '5' and '17' and Express why resulting value of last two
queries are same.
12. Extract 4 letters from 3th position of this word 'INFOSYS'.
13. What is the ASCII value of 'a' and 'S'.
14. What is Length of this word 'INFOSYS' AND change 'S' with 'T'.
15. Retrieve the Names and Address of the Members who belong to Kolkata.
16. Retrieve the Name of Books, where Cost prices are between 300 and 500.
17. List the Name of the Members whose Membership type is “HALF YEARLY”.
18. List the Name of the Members who open their account in the year of 2011.
19. Retrieve the Penalty Amount of the Members who has taken the book “LET US C”.
20. Retrieve the no of Max books allowed to a Member, who has issued books on January.
21. Give the Names of the Members who have not issued any books.
22. Give the Name and Category of the books whose cost is not recorded.
23. List all the books that are written by Author ‘’Loni’’ and has Price less than 600.
24. List the Issue details for the Books that are not returned yet.

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)
25. List all the Books that belong to any one of the following categories Science, Database.
26. List all the Members in the descending order of Penalty due on them.
27. List all the Books in ascending order of category and descending order of price.
28. List all the Books that contain word ‘SQL’ in the Name of the Book.
29. List all the Members whose Name starts with S.
30. List all the Members whose Name starts with S or A and contains letter T in it.
31. List the Entire Book name in INIT CAP and Author Name in UPPER case in the descending order
of the Book Name.
32. 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.
33. List all the Members that became the Member in the year 2011.

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 3

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. Display the MEMBER ID and the NO OF BOOKS for each member that has issued more than 1
books.

4. Display the MEMBER ID, BOOK NO and NO OF TIMES the same book is issued by the
MEMBER in the descending order of count.

5. Select all information of Book with 2nd Maximum Cost.

6. Copy the MEMBER, BOOKS and ISSUE tables and MEMBER_COPY, BOOKS_COPY,
ISSUE_COPY respectively.
7. Create a table named QUERY1 with two attributes as BOOK_NO, ISSUE_DATE and copy all
information about BOOK_NO and ISSUE_DATE from ISSUE table to QUERY1 table.
8. Create and store BOOK_NAME, AUTHOR_NAME and COST to QUERY2 table where cost is
greater than 300.
9. Insert BOOK_NAME, AUTHOR_NAME and COST to QUERY2 table where cost is less than
300.
10. ADD an attribute name AVAILABLE with data type NUMBER (5) in the BOOKS_COPY table
and fill up the new attribute with data.
11. Change the Data type of CATEGORY attribute to VARCHAR2 (15) in BOOKS_COPY table.
12. Create a SAVE POINT after that do some delete or update operation and roll back the previous
scenario.
13. Create a New USER, Log in to new USER; provide permission of selection on BOOK table to the
new USER. Then provide DBA privilege to the new USER.

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 4

1) Write a PL/SQL program where take input of two numbers and display the largest number.

2) Write a PL/SQL program where take input of any number and display whether it is even or odd.

3) Write a PL/SQL program where take input of any number and find factorial of the given number.

4) Write a PL/SQL program where check a year leap year or not. Take a year as user input and check it
is leap year or not.

5) Write a PL/SQL program where take a string as input and print the reverse of it.

6) Create a table named CIRCLE with two attributes RADIUS number(3) and AREA number(10,3),
then write a PL/SQL program which can calculate area for every radius up to 10 and insert into the
table. (Use while and for loop individually).

7) Write a PL/SQL program which can update cost value of corresponding book number of the
BOOKS_COPY Table.

✓ INPUT: BOOK_NO, NEW COST,

✓ CONDITION: Old cost value will less than 450 and new cost value will less
Than900 otherwise provide an error massage.

8) Write a PL/SQL Program which take MEMBER_ID as input and provide the corresponding
MEMBER_NAME, MEMBER_ADDRESS AND FEES PAID.

9) Write a PL/SQL program which can take a String as an input and display it without any space and
also count the no of space available in the input string.

10) Take an input of any string and display each word in a separate line.

11) Take an input of any Member Number and display the Member Name in upper case and lower case.

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 5

1. Write a PL/SQL program which can update the cost of BOOKS_COPY table with 10 more cost
where cost is less than 500 and show how many rows are affected (Use Implicit Cursor
SQL%ROWCOUNT).

2. Write a PL/SQL program which can increment the value of MAX_BOOKS_ALLOWED of


MEMBER_COPY table with 2 where MEMBER_ID = 5, and show a message if update is
possible. (Use Implicit Cursor SQL%FOUND).

3. Write a PL/SQL Program using Explicit Cursor and show the Member_ID, Member Name for
every attribute of Member.

4. Write a PL/SQL program using Explicit Cursor which deducts the value of Max_Books_Allowed
from MEMBER_COPY table. Deduct value means the value that how many times this member
accesses the books. After deduction if value of Max_Books_Allowed is less than 0 the do not
update it and show an error message.

5. Create a table BOOK_UPDATE with attribute BOOK_NO, BOOK_NAME, INCREAMENT


VALUE, UPDATE_DATE and write a PL/SQL program using Explicit Cursor which can update
the cost value of BOOKS_COPY table with 10 and 20 where category is Science and database
respectively, and if update is possible then insert BOOK_NO, BOOK_NAME, INCREAMENT
VALUE, SYSDATE to the BOOK_UPDATE table.

6. Write a PL/SQL program using Explicit Cursor which can display the all information of 5 books
from BOOK_COPY table according to the higher cost.

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 6
1) Write a PL/SQL PROCEDURE to compute addition between two numbers and use the different
modes (IN, OUT, IN OUT) of data type in input variables which are used on creating PROCEDURE.

2) Write the SQL query to show the error of the PROCEDURE compilation.

3) Write a PL/SQL Procedure which take MEMBER_ID as an input and show the corresponding
MEMBER_NAME.

4) Write a PL/SQL procedure which take BOOK_CATEGORY as an input and show the corresponding
BOOK_NAME.

5) Write a PL/SQL procedure which can take the BOOK_ID as user input and update the cost with 50
more cost in BOOKS_COPY table.

6) Write the PL/SQL function which can compute the multiplication between two numbers and return
the value to the normal PL/SQL program which can show the output.

7) Write a PL/SQL function which take COST of the book as the user input and retrieve the BOOK
NAME from the BOOKS table.

8) Write a PL/SQL function which take AUTHOR_NAME of the book as the user input and retrieve the
BOOK NAME from the BOOKS table.

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 7
1) Create a PL/SQL Trigger which can fire on MEMBER_COPY table and raise an application
error when delete a row from this table.
2) Create a PL/SQL Trigger which can fire on BOOK_COPY table and raise an application error
when you are going to update cost less than 200 against any book.
3) Write a SQL command to disable, enable and drop the individual trigger and disable or enable
all trigger against a table.
4) Write a PL/SQL program which a show the Member_Name against a Member_ID and also
raise an application error is no data found. (Using NO_DATA_FOUND Exception)
5) Create a table named CHANGE with three attribute Book_ID number(5), Change_Date date,
Change_type varchar(10); Then Write a PL/SQL Trigger which can fire on BOOK_COPY
table when you update or delete any particular Book and automatically insert a row into
CHANGE table with the value of changed Book_NO, sysdate and Type of change
(Update/Delete).
6) Create a PL/SQL Trigger which can fire on row insertion of ISSUE_COPY table and throw a
user define exception when insert day is Wednesday or Sunday.
7) Create a PL/SQL Trigger which can fire on insertion of ISSUE_COPY table and provide an
application error if ISSUE_DATE is greater than SYSDATE.
8) Create a table named COUNTROW which can store the no of entries of BOOKS_COPY table
and create a PL/SQL Trigger which can fire on insert, delete or update of BOOKS_COPY
table and automatically change the value of COUNTROW table.

Suprativ Saha
Asst. Prof., Dept. of CSE, BWU
Brainware University
Department of Computer Science and Engineering
B-Tech in Computer Science and Engineering (3rd Year, 5th SEM)
Database Management System Lab (PCC-CS591)

ASSIGNMENT 8
1) Create a Table named SEQUENCE_TEST with 3 attributes ID Number (5), NAME Varchar2
(20), MARKS Number (10). After that Create a SEQUENCE which is associated with ID of
SEQUENCE_TEST table.
➢ Parameters of SEQUENCE:
✓ Increment By 1,
✓ Start with 5,
✓ Maximum value 10,
✓ Minimum Value 3,
✓ Cycle/No cycle (Test with 2 different types, at first do Cycle),
✓ CASHE 6,
✓ NO ORDER
2) Write a SQL query to insert value into SEQUENCE_TEST table using this pre created sequence
and Test the SEQUENCE.
3) Write a SQL Query to jump the Sequence value with 1 at a particular point of time.
4) Write a SQL Query to check the current Sequence value.
5) Alter the parameters of SEQUENCE.
➢ Parameters of SEQUENCE:
✓ Increment By 2,
✓ Maximum value 12,
✓ Minimum Value 1,
✓ No Cycle,
✓ CASHE 6,
✓ NO ORDER

6) Write a SQL Query to Drop the Sequence.

7) Create a Simple or Composite or Unique INDEX on ID column of SEQUENCE_TEST table.


8) Create a Function based INDEX.
9) Write a SQL Query to Drop the INDEX.
10) Create a View which can store Author Name and No of books written by this author.
11) Test the INSERT, SELECT, UPDATE, DELETE operation on View.
12) Write a SQL Query to Drop the VIEW.
Suprativ Saha
Asst. Prof., Dept. of CSE, BWU

You might also like