You are on page 1of 65

LAB Manual

Relational Database Management System

Navrachana University
School of Engineering and Technology
Department of Information Technology
Semester – III

Enrolment ID: 19125052


Student Name: Veer Shah
Course In charge: Sushma Vankhede

Year: 2020-2021
Index

Performance Submission
Sr. No. Lab Exercise Marks
Date Date
1 Lab Exercise 1 28/07/20 10/08/20
2 Lab Exercise 2 29/07/20 10/08/20
3 Lab Exercise 3 04/08/20 10/08/20
4 Lab Exercise 4 05/08/20 10/08/20
5 Lab Exercise 5 18/08/20 10/08/20
6 Lab Exercise 6 (25,26)/08/20 10/08/20
7 Lab Exercise 7 01/09/20 10/08/20
8 Lab Exercise 8 02/09/20 10/08/20
9 Lab Exercise 9 08/09/20 10/08/20
10 Lab Exercise 10 08/09/20 10/08/20
LAB-TASK-1(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052
• Consider the following schema

Employee {Eid, Ename, salary, dept_id}

Dept{ Did, Dname }

• Write the SQL queries to create above table.

1. Display the column names, data type and size and of table Employee.

2. Display the column names, data type and size and of table Dept.

3. Add a new column ‘City’ into Employee table with varchar2 datatype and size 10.
4. Update the size of salary attribute to ‘5’.

5. Add new column as ‘Job’ to the Employee table.

6. Add the new attribute as ‘Location’ to dept table.

7. The employee who working in department No. 20 and whose employee id is 102
now shifted to ‘Surat’ city.
8. Increase the salary of employees by 1000 if his/her salary is greater than 12000 or equal to
and increase it by 500 if its less than 12000.
LAB-TASK-2(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052

• Consider the structure of ‘Book’ Table as

Book_Master {Bookid, BookName, SubCode, Autor, No_of_copies}

• Write SQL queries for the following:

1. Add new column ‘Price’ in Book_master Table.


2. Modify the datatype of ‘Book_id’ attribute as Varchar2.

3. Insert the 10 rows in Book_master Table.

Book_id BookName SubCode Author No_of_copies Price

B1001 C language CS101 Yashwant Kanetkar 10 650

B1002 Finding Inner Peace NV101 Blissford 03 520

B1003 Software Engineering CS331 Rogger Pressman 15 750

B1004 ‘DBMS’ IT237 ‘korth’ 12 485

B1005 ‘Introduction to SQL’ IT237 ‘Nawathe’ 08 390

B1006 Software Wizardry CS352 Abugov 05 470

B1007 Introduction to Algorithms IT216 Cormen 14 465

B1008 Code Complete CS410 Steve McConnell 10 540

B1009 Database System Concepts IT237 Abraham Silberschatz 15 730

B1010 Algorithm Design IT216 Jon Kleinberg 13 510


4. Display the details of book whose price is less than 500.

5. Display the book id and book name of books whose Author is ‘Abugov’.
6. Display the details of books whose 10 or more copies are available in the database.

7. Display the Name of books which are available for subject code ‘IT216’.

8. Modify the No_of _copies of ‘DBMS’ book to 20.

9. Display the name of books whose book name ends with character ‘s’
10. Modify the price of books as given bellow:
a. Increase 50 rupees whose price < 400,

b. Increase by 70 rupees if price >=400 and price <700.

c. Increase by 100 rupees if price >=700 and price<=1000.


11. Display name of book whose name start with s.

12. Display a book whose less than 6 copies are there in database.

13. Display details of book whose price is between 500-700.

14. Display book detail whose author name starts with letter A.

15. Change the name of author of book”intodruction to SQL ” from Nawathe to Kurth.
16. Change the number of copies from 10 to 20.

17. Display details of books whose number of copies is between 10-20.


LAB-TASK-1(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052
• Consider the following schema
• Dept
Dept_id Dname Location
10 IT MUMBAI
20 SALES SAURASHTRA
30 HR SURAT

• Emp
Eid Ename Job Salary DNo
101 Nisha IT Head 60000 10
102 Meet Salesman 15000 20
103 Aaisha HR 30000 30
104 Keshav s/w Developer 35000 10
105 Leena S/w Tester 32000 10
106 Mehul Sales Executive 25000 20

1. Display the sum of all salaries.


2. Display the minimum salary from department number 10.

3. Calculate the average salary of employees who are working in department no. 20
and 30.

4. Display average salary of department 20.

5. Display maximum and minimum salary from each department.

6. Display second max salary from emp table.


7. Display department name wise average salary.

8. Find maximum salary drawn by the employees from department number 10 and
20.

9. Add new attribute commission in emp table.

10. Add the commission as 5000 rupees whose salary is less than or equal to 30000
or greater than 20000 and add commission as 2500 whose salary is less
than or equal to 20000.
11. Find total number of employees who get some commission.

12. Find the total number of employees works in department No. 20.

13. Display the total number of employees who gets the commission more than
3500.
14. Display the average salary of each department in descending order

15. Display the total number of employees whose salary is greater than average
salary of all employees.
LAB 4-TASK 1(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052

1. Create table Orders with the fields ORDER_NO , ORDER_DATE, CUSTOMER_ID


,CUSTOMER_NAME, PAID ,AMOUNT.
Ans:

2. Find the maximum value order from the table Orders:


Ans:

3. Find the sum of the values of Amount column.


Ans:
4. Find the sum of the values of Amount column where the Amount is greater than 8000.
Ans:

5. Find the sum of distinct Amount from the table Orders.


Ans:

6. Find the sum of Amount of each individual customer and groups the result using
customer name.
Ans:

7. Add column quantity in the table Orders.


Ans:
8. Find the average paid of only those products where quantity is greater than 50.
Ans:

9. Find the average Amount of products.


Ans:

10. Find the minimum value order from the table Orders:
Ans:
LAB 4-TASK 2(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052

• Create a table with fields- ORD_NO , PURCH_AMT ,ORD_DATE, CUSTOMER_ID ,


SALESMAN_ID.

1. Write a SQL statement to find the total purchase amount of all orders.
Ans:

2. Write a SQL statement to find the average purchase amount of all orders.
Ans:
3. Write a SQL statement to get the maximum purchase amount of all the orders.
Ans:

4. Write a SQL statement to get the minimum purchase amount of all the orders.
Ans:

5. Write a SQL statement to find the highest purchase amount ordered by the
each customer with their ID and highest purchase amount.
Ans:
6. Write a SQL statement to find the highest purchase amount ordered by the each
customer on a particular date with their ID, order date and highest purchase
amount.
Ans:

7. Write a SQL statement to find the highest purchase amount on a date '2012-08-17' for
each salesman with their ID. 
Ans:

8. Write a SQL statement to find the highest purchase amount with their ID and order
date, for only those customers who have highest purchase amount in a day is more
than 2000.
Ans:
9. Write a SQL statement to find the highest purchase amount with their ID, for only
those customers whose ID is within the range 3002 and 3007.
Ans:
LAB-5(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052

Part 1
Q1 Create the tables as per above schema and set the different keys as per requirement
Q2 Insert 5 records in each table.
Q3 List the titles of all movies directed by ‘Subhash Ghai’

Q4 Display the name of all actors whose name starts with ‘D’.

Q5 Find the movie names where one or more actors acted in two or more movies.

Q6 Update rating of all movies directed by ‘Nagraj Manjule’ to 5.


Q7 Display Movie title and movie language directed by ‘D495’

Q8 Display the details of all female Actors whose Name have the second last letter ‘y’;

Q9 Display all the movies of ‘SSR’ released in year 2020

Q10 Display the name of all actors who have done role of ‘Politician’;
Part 2

Q1 Create A Table EMP And DEPT Using the Following Information.


DEPT
DEPTNO NUMBER (2) PRIMARY KEY PK_DEPT

DNAME VARCHAR2 (10) UNIQUE UQ_DEPT

LOC VARCHAR2(10)

EMP
EMPNO NUMBER (4) PRIMARY KEY PK_EMP

ENAME VARCHAR2(10) UNIQUE UK_ENAME

JOB VARCHAR2(10)

MGR NUMBER (4)

HIREDATE DATE

CK_SAL (SAL >10000


SALARY NUMBER (8,2) CHECK CONSTRAINT
AND SAL <200000.

COMM NUMBER (8,2)

DEPTNO NUMBER (2) FOREIGN KEY FK_DEPT


Q2 Drop the constraints UQ_ENAME from

Q3 Insert only the records of employee number, name, and salary into EMP table.
Q4 Update the salary by 10% hike to analysts working in department number 20 & 30.
Q5 Give all the employees a commission of Rs 500

Q6 Modify the column ENAME present in the EMP table with the following information
given below: CHAR(20)

Q7 Add two columns to the table EMP with the following information in one single
ALTERCOMMAND.[(Gender varchar2 with size 1), (Place varchar2 with size 10)].
Q8 Add new column as company_name to DEPT table and assign default value as ‘Reliance’ to
the new records
Q9 Add a new column PINCODE with not null constraints to the existing table DEPT
Q10 Disable the constraints PK_DEPTNO present in the DEPT table.
LAB-6(RDBMS)
NAME: VEER SHAH
B.TECH-S.Y-IT
ID-19125052
• Consider the schema for University Database:

STUDENT (USN, SName, Address, Phone,Gender)


SEMSEC (SSID, Sem, Sec)
CLASS (USN, SSID)
SUBJECT (Subcode, Title, Sem, Credits)
IAMARKS (USN, Subcode, SSID, Test1, Test2, Test3, Final_IA)

1. Consider the above database and draw the Entity Relationship Model.
2. Draw the schema diagram for the above database.

• Create the above relations.

• Insert 5 records in each table.


3. Write SQL queries to
I. list all the student details studying in fourth semester ‘C’ section.
II. Compute the total number of male and female students in each semester and in
each section.

III. Create a view of Test1 marks of student USN ‘1AIT101’ in all subjects.

IV. Categorize students based on the Following criterion:


If Final_IA = 17 to 20 then CAT = ‘Outstanding’ If
Final_IA = 12 to 16 then CAT = ‘Average’
If Final_IA < 12 then CAT = ‘Weak’

V. Give these details only for 8th semester A, B, and C section students.

Task - 2 (26-8-2020)
1. Give University student number and Student Name of the students who are in
semester -4.

2. Add unique constraint in phone in student table.

3. Add NOT NULL constraint in name column.

4. Give the details of the subject whose title starts with ‘D’and ends with ‘M’.

5. Find out the details of student who got highest and lowest marks in Final
internal assessment from all semester
6. Get the details of student who have secured less than average marks of
students in Test 2.

7. Find out Maximum and minimum marks of student semester wise in Test 3.

8. Get the student name of those students who got third highest marks in
Semester 6 and section ‘B’.
9. Get the subject details whose credits are 3 or more.

10. Find the Maximum Marks of students in Semester 1 to 8 gender wise.


LAB-TASK-7(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052
• Create the following table

Employee Info (Emp_Id , Emp_FName , Emp_LName,Department,Project,Address,D.O.B,


Gender, Salary).

Q1 Write a query to fetch the EmpFname from the EmployeeInfo table whose salary is equal
to average salary.
Q2 Write a query to fetch the number of employees working in the department ‘HR’.

Q3 Write a query to retrieve the first four characters of EmpLname from the Employee Info table.

Q4 Write a query to find all the employees whose salary is between 50000 to 100000.

Q5 Write a query to find the names of employees that begin with ‘S’ and have 4th
character as ‘A’.
Q6 Write a query to retrieve the EmpFname and EmpLname in a single column as
“FullName”. The first name and the last name must be separated with space.

Q7 Write a query to fetch all the records from the EmployeeInfo table ordered by
EmpLname in descending order and Department in the ascending order.
Q8 Write a query to fetch details of employees whose EmpLname ends with an alphabet
‘A’ and contains five alphabets.

Q9 Write a query to fetch details of all employees excluding the employees with first
names, “Sanjay” and “Sonia” from the EmployeeInfo table.

Q10 Write a query to fetch details of employees with the address as “DELHI”.
Q11 Write a query to display the first and the last record from the EmployeeInfo table.

Q12 Write an SQL query to fetch the count of employees working in project ‘P1’.

Q13 Write an SQL queries to fetch those employees who live in Toronto and working under
project P1.

Q14 Write an SQL query to find the employee id whose salary lies in the range of 9000 and
15000.
Q15 Write an SQL queries to fetch all the employees who either live in California or
working under project P1.
LAB-TASK-8(RDBMS)
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125054

• ABS= A mathematical function that returns the absolute (positive) value of


the specified numeric expression

• CEIL = function is used to get the smallest integer which is greater than, or
equal to, the specified numeric expression

.
• FLOOR = function returns the largest integer value that is smaller than or
equal to a number

• The POWER function returns the value of a number raised to the power of
another number.
• The ROUND function rounds a number to a specified number of
decimal places. Tip: Also look at the FLOOR and CEILING functions.

• The SQRT function returns the square root of a number.

• SQL LN function returns the natural logarithm of n, where n is greater than 0

• The LOG function returns the natural logarithm of a specified number, or the
logarithm of the number to the specified base

• The MOD function returns the remainder of a number divided by another


number
• The function SIGN returns the sign for the numeric expression. It returns a
value of -1 for negative expressions, a value of 0 for zero expressions and a
value of +1 for positive expressions.

• COS function is a mathematical function that returns the trigonometric


cosine of the specified angle – measured in radians

• EXP function returns e raised to the n-th power

.
LAB-TASK-10
NAME:VEER SHAH
B.TECH-S.Y-IT
ID-19125052

• Consider the following schema for employee database:


Workers(Worker_Id, First_Name, Last_Name, Salary, DateOfJoining, Department)
Bonus(WorkersRef_Id, BonusDate, Bonus_Amt)

Q1 Draw ER diagram & Schema diagram for the above schema.


Q2 Create tables using SQL.

Q3 Insert 8 rows for each table.


Q4 Write a SQL query to fetch unique values of DEPARTMENT from Worker table.

Q5 Write a SQL query to find the position of the alphabet (‘a’) in the first name column ‘Amitabh’
from Worker table.

Q6 Write a SQL query to print details for Workers with the first name as “Vipul” and “Satish” from
Worker table.

Q7 Write a SQL query to print details of the Workers who have joined in Feb’2014.

Q8 Write a SQL query to fetch worker names with salaries >= 50000 and <= 100000.
Q9 Write a SQL query to show the second highest salary from a table.

Q10 Write a SQL query to fetch the first 50% records from a table.

Q11 Write a SQL query to print the name of employees having the highest salary in each
department.

Q12 Write a SQL query to fetch three max salaries from a table.
Q13 Write a SQL query to fetch three min salaries from a table.

Q14 Write a SQL query to fetch departments along with the total salaries paid for each of them.

Q15 Write a SQL query to fetch the names of workers who earn the highest salary.
Create a table with attributes- ord_no ,customer name, purch_amt ,ord_date, customer_id ,
salesman_id.

1. Write a SQL statement to find the total purchase amount of all orders.

2. Write a SQL statement to find the average purchase amount of all orders.

3. Write a SQL statement to get the maximum purchase amount of all the orders.
4. Write a SQL statement to get the minimum purchase amount of all the orders

5. Write a SQL statement to find the highest purchase amount ordered by the each customer with their
ID and highest purchase amount.

6. Write a SQL statement to find the highest purchase amount ordered by the each customer on a
particular date with their ID, order date and highest purchase amount.
7. Write a SQL statement to find the highest purchase amount on a date '2012-08- 17' for each salesman
with their ID.

8. Write a SQL statement to find the highest purchase amount with their ID, for only those customers
whose ID is within the range 3002 and 3007.

9. Display all columns and datatypes and size in table.

10.How many characters does the customer name: “AMIT” have in the table
11. Display output of order_no field as PRODUCT_No in table.

12. Display only one record from table

13. Add a column: Product to the existing table with data type varchar and size 20

14.Write a query to extract the customer name, customer_id from the table where the
purchase_amount are greater than 50,000.
Create an inter University Database with the following relations. Include at least four attributes for
each table. Also draw ER diagram for the same.

• University • Department • Program • Course • Syllabus • Faculty(Teacher)

a) Create above tables and mention primary keys and foreign keys.
b) Insert at least 5 relevant records in each of the created tables.

c) Write following SQL queries based on Database created.

i) List of Universities situated at Gujarat.

ii) List of all Departments of Navrachana University.

iii) Find the location of ITM University.

iv)List of all Programs run by University of Jammu.


v) List of Universities that run Program "MCA".

vi) List of Courses of "MCA" run by Parul University.

vii) List of Faculties specialized in "Information Security" across different universities.

viii)Syllabus of "Computer Architecture" of different Universities.

ix) List of all faculties of Department of Computer Science of Navrachana University.

x) Find the University which has maximum Departments.

You might also like