Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Babu Madhav Institute of Information Technology

B.Sc. (IT)
CS3019: Introduction to Database Management System
Practical Set -1
Write down the syntax for the following operations
a) Creating database
b) How to use particular database
c) View all databases available
d) Dropping database
e) Creating table
f) Display list of created tables
g) Displaying structure of the table
h) Dropping table created
i) Inserting records in table
j) Deleting records from particular table

a. Create a database named “Company” and create following table also insert at least 10 records in each
table.
Entity Attributes
Employee Emp_Id, emp_name, emp_designation, emp_contact, emp_city, salary
Department department_id, department_name, department_location
Project project_number, emp_Id, duration, budget, client_name

b. Create a database named “Library” and create following table also insert at least 10 records in each
table
Entity Attributes
Member Card_Number , name, surname, address, birthdate, contact
Book Book_Id, book_name, book_type, price, title, publisher_name, ISBN_number,
quantity
Issue Book_Id, card_number,issue_Date, return_Date, penalty

c. Create a database name “Hospital” and create following table also insert at least 10 records in each
table.
Entity Attributes
Doctor doctor_id, doctor_name, doctor_specialization, doctor_department
Patient patient_number, patient_name, gender, address, contact, city
Appointment appointment_number, patient_name, doctor_name, appoint_date, start_time,
end_time

MS. KAJAL PATIL 1


d. Create a database name “Cart” and create following table also insert at least 10 records in each table.
Entity Attributes
ProductMaster Product_Id, product_name, category, description, price, quantity
CategoryMaster Category_Id, category_name
OrderMaster order_number, product_Id, quantity, order_Date, orderStatus
FeedbackMaster Feedback_Id, customer_Number, Feedback_Description
CustomerMaster customerNumber, name, contact, gender, date_of_birth, email_address, address,
city, pincode

e. Create a database name “BMIIT” and create following table also insert at least 10 records in each table.
Entity Attributes
Student Enrollnment_number, fname, lname, contact, city, date_of_birth, emailAddress
Faculty Faculty_Id, faculty_name, designation, subject, date_of_joining, experience
Subject Subject_id, subject_name, subject_type,is_elective, credit, effectiveYear
Course Course_id, course_name, course_Duration
Leave Leave_Id, enrollnment_number, leave_type, leav_Description, fromDate, ToDate,
FromTime, ToTime

ASSESSMENT
FACULTY SIGNATURE
DATE
Comment, if any

MS. KAJAL PATIL 2


Babu Madhav Institute of Information Technology
B.Sc. (IT)
CS3019: Introduction to Database Management System
Practical Set -2
Write down the syntax for the following to perform the operation on the table.
a) To add new column
b) To drop column
c) To add new column at a specify location
d) To add new column as the first column
e) To modify existing columns
f) To modify existing column and shift at a specify location
g) To modify existing column and make it the first column
h) To rename existing column
i) To drop any particular column

a. Create a database named “UTU” and create table student , also insert at least 5 records in table

Table : Student
Column Datatype
Fname Varchar
Lname Varchar
Contact bigint
Date_of_birth date
Email Varchar

Perform following operation on the table


1. Add a column named “city” with data type varchar and size 15
2. Add a column named “address” with data type varchar and size 15
3. Add a column named “roll number” with data type int
4. Add a column named “gender” with data type varchar and size 7
5. Modify the size of column “address” to 50
6. Modify the data type of the column gender to “char” and size as “1”
7. Rename the column Email to “Email id”
8. Change the column Date_of_birth to “DOB” and also immediately shift after gender column.
9. Add column date of join and datatype as “date” and make that column as the first column of the table.
10. Drop the column name “date of join” from the table
11. Rename table name as “tblStudent”
12. Drop table tblStudent from the database.

ASSESSMENT
FACULTY SIGNATURE
DATE
Comment, if any

MS. KAJAL PATIL 3


Babu Madhav Institute of Information Technology
B.Sc. (IT)
CS3019: Introduction to Database Management System
Practical Set -3
a. Answer the following questions:
a) Define constraint
b) Purpose of NOT NULL constraint
c) Differentiate between UNIQUE and PRIMARY KEY
d) Write down the purpose of AUTO INCREMENT

b. Create a database named “UTU” and create table student with the following constraints mentioned
below.
NOTE: Read below mentioned constraint first and then create table and accordingly enter 10 records
into the table
Table : Student
Column Datatype
Stud_id int
Fname Varchar
Lname Varchar
Gender Varchar(10)
Contact bigint
Date_of_birth date
Email Varchar
Age int

Perform following operation on the table


1. Set PRIMARY KEY and AUTO INCREMENT to the column stud_id
2. Set NOT NULL constraint on column FNAME, LNAME,DATE_OF_BIRTH
3. Set UNIQUE constraint to the Email column
4. Set CHECK constraint to the age column (Condition: age must be greater than 18)
5. Set DEFAULT constraint to the gender column as “MALE”

ASSESSMENT
FACULTY SIGNATURE
DATE
Comment, if any

MS. KAJAL PATIL 4


Babu Madhav Institute of Information Technology
B.Sc. (IT)
CS3019: Introduction to Database Management System
Practical Set -4
a. Create a database named “Company” and create table Employee with the following constraints
mentioned also enter 10 records.

Table : Employee master


Column Datatype Constraint
Emp_id int Primary key Auto increment
Emp_fname Varchar Not null
Emp_lname Varchar Not null
Gender varchar
Department Varchar Not null
Contact bigint Not null
Email Varchar Unique
Salary int
city Varchar
Perform following operation on the table
1. Retrieve all the records of employee.
2. Display employee id, name and department of all employee.
3. Manager of the company wants to know employee first name who are coming from Surat.
4. Retrieve employee first name along with date of joining.
5. View the list of male employees.
6. Display employee name along with salary whose department name is HR.
7. List all the records of employee whose salary is greater than or equal to 25,000.
8. Display employee name and department whose salary is less than 10,000.
9. Display employee name of employee whose ID is 102.
10. Retrieve all the records of employee whose employee id 108.
11. Select all the fields from employee master where city is ‘Surat’ and ‘Bharuch’.
12. Display employee name and department from employee master whose city is ‘Valsad’ or ‘Surat’.
13. Retrieve all the records of employee whose salary is greater than 20,000 and department is IT.
14. Display all the records of employees who are not for Surat city.
15. Display all the records of employee in ascending order using first name of employee.
16. Display employee first name, gender, city and salary in descending order by city column.
17. Retrieve all the records of employee from employee master sorted ascending by city and descending by
employee name.
18. Display first three records of employees.
19. Retrieve first four records of employees who are coming from Surat city.
20. Display first five records of employees who salary is greater than or equal to 30,000 and department is IT.

ASSESSMENT
FACULTY SIGNATURE
DATE

MS. KAJAL PATIL 5


Babu Madhav Institute of Information Technology
B.Sc. (IT)
CS3019: Introduction to Database Management System
Practical Set -5

a. Create a database named “Library” and create table Book master with the following constraints
mentioned also enter 10 records.

Table : Book_master
Column Datatype Constraint
Book_id int Primary key Auto increment
Book_name Varchar Unique
Author name Varchar Not null
Quantity int Not null
Price Int/float/decimal Not null
Perform following operation on the table
1. Display all records of book with a book Name starting with "D".
2. Display book name and price with a book name that have “aj” in any position.
3. Retrieve book name, author name and price with an author name that have “a” in the second position.
4. View all book details with a book name that starts with "a" and are at least 3 characters in length.
5. View all book details with a book name that starts with "a" and ends with "o".
6. Selects all book details with an author name that does NOT start with "a".
7. View author name with a book name starting with “ch”.
8. View all book name with an author name starting with any character, followed by "al".
9. Retrieve book id, name and price whose author are “Vikram Seth”, “Chetan Bhagat” and “Kapil Dev”.
10. Retrieve book id, name whose author are not “Chetan Bhagat”.
11. Display book name and quantity whose prices is more than 1500 but less than 500.
12. Retrieve book details whose price is 700 and quantity is 20.
13. View all the book details whose price is between 450 and 600.
14. View all the book details whose price is not between 150 and 200.
15. Delete all the records of book whose book id is 1005.
16. Remove all the details of book whose author are Mr. Roy.

ASSESSMENT
FACULTY SIGNATURE
DATE
Comment, if any

MS. KAJAL PATIL 6


Babu Madhav Institute of Information Technology
B.Sc. (IT)
CS3019: Introduction to Database Management System
Practical Set -6
a. Create a database named “Company” and create table Employee with the following constraints
mentioned also enter 10 records.

Column Constraint
Employee ID Primary key
First name Not null
Last name null
Email Unique
Phone number Not null
Job Title varchar
Hire Date Not null
Salary Not null
Perform following operation on the table
1. Write a query to list the number of jobs available in the employees table.
2. Write a query to get the total salaries payable to employees.
3. Write a query to get the minimum salary from employees table.
4. Write a query to get the maximum salary of an employee working as a Programmer.
5. Write a query to get the average salary and number of employees working as a job title programmer.
6. Write a query to get the highest, lowest, sum, and average salary of all employees.
7. Write a query to get the difference between the highest and lowest salaries.
8. Write a query to find the employee ID and the salary of the lowest-paid employee for that manager.
9. Write a query to get the average salary for each job excluding programmer.
10. Write a query to get the job title and maximum salary of the employees where maximum salary is greater
than or equal to Rs. 4000.

ASSESSMENT
FACULTY SIGNATURE
DATE
Comment, if any

MS. KAJAL PATIL 7


Babu Madhav Institute of Information Technology
B.Sc. (IT)
CS3019: Introduction to Database Management System
Miscellaneous Practical Set 8
a. Create a database named “Sales” and create below mentioned tables with the following constraints
and also enter records.
Table name : tbl_Dealer
DCODE DNAME
101 Reliable Stationaries
102 Classic plastic
103 Clear deal
104 Krishna Cosmetic
105 Surbhi collection
Table name : Item_master

ItemID NAME MANUFACTURER PRICE QTY STOCKDATE DCODE


TP01 Talcum powder Persona 40 45 11-02-18 104
FW05 Face Wash Attitude 45 55 15-04-18 105
BS01 Bath Soap Persona 55 80 11-02-18 104
SH06 Shampoo Patanjali 12 50 05-01-17 105
FW12 Face Wash Loreal 95 45 05-01-16 105
S5005 Ball pen 0.5 Nataraj Classic 16 100 31-03-10 102
S5003 Ball pen 0.25 Nataraj Classic 20 150 01-01-10 102
S5002 Gel Pen Premium Pilot juice 14 125 14-02-10 101
S5006 Gen Pen Classic Pilot juice 22 200 01-01-10 101
S5001 Eraser S Apsara 15 210 19-03-09 102
S5004 Eraser L Apsara 10 60 12-12-09 102
S5009 Sharpener Nataraj Classic 18 160 23-01-09 103

Table Name: tblClient


Cid Fname City ItemID
04 Raj Surat FW05
07 Priya Navsari S5009
12 Sneha Surat SH06
15 Krina NAvsari S5005
16 Sejal Vapi TP01
28 Ram Valsad BS01
33 Neha Bardoli FW12
61 Bhautik Valsad S5003
77 Shreyanshu Vapi S5006
35 Aditya Surat FW05
87 Hitesh Anand FW12
31 Pranjal Baroda S5009
83 Viren Anand TP01
40 Vraj Surat S5003

MS. KAJAL PATIL 8


Perform following operation on the table given.
1. Display only the name and price of items, whose manufacturer is “Persona”.
2. Count the total number of manufacturers.
3. Display all the client’s details, whose names starts from "Bh".
4. Display the items details of all different types of pens.
5. Display only the name and price of product along with quantity, whose price is more than80
6. Show only the item and its price of those items, whose price is less equal to 20.
7. Display the details of those items, whose dealer code is 102 or quantity is more than 100.
8. Show the details of items, whose quantity is in the range of 50 to 100.
9. Increase the price of items by 10.
10. Decrease the quantity of items by 30.
11. Update the price of items by increasing 15%.
12. Find the maximum and minimum price of item in a single query.
13. Calculate the average of item price.
14. Calculate the total amount of items and find the average of it.
15. Show all item names with its price and stockdate.
16. Arrange all the client’s details according to the item in ascending order.
17. Display details of all stock items in decreasing order of StockDate.
18. Display only the names with cities of clients, whose city is not SURAT, VAPI andVALSAD
using “NOT IN” operator.
19. Display first three records of customer.
20. Display item names in descending order.
21. Show all the details for clients in upper case.
22. Display all the items in capital letters.
23. Display only the item names with its length.
24. Show all the manufacturers of items in small letters.
25. Add a column named “GENDER” of datatype “char” and size “1” immediately after client
name.
26. Set the gender of all clients.
27. Count the total number of dealers from item table.
28. Add a column named “LOCATION” of datatype “varchar” and size “15” in dealer’s table.
29. Set the location of dealer “Clear Deals” as ‘Mumbai’.
30. Check whether any location of any dealer is NULL.
31. Remove the LOCATION column from the dealer’s table.
32. Count total number of clients from different cities.
33. Count total number of male clients from different cities.
34. Find total number of male and female clients from different cities.
35. Count total number of clients from “Mumbai” city.
36. Find total items of manufacturers.
37. Display the maximum price of items for each dealer individually as per DCODE from theitem
table.
38. Find the total amount price of items for the date “01-01-2010”.
39. Remove the details of those clients, whose city is “Bardoli”.
40. Delete all the records from all the tables.

ASSESSMENT
FACULTY SIGNATURE
DATE
Comment, if any

MS. KAJAL PATIL 9


Babu Madhav Institute of Information Technology
B.Sc. (IT)
CS3019: Introduction to Database Management System
Practical Set -9
b. Create a database named “Company” and create following table with the appropriate
constraints.

Sample table: salesman

salesman_id | name | city | commission


-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12

Sample table: customer


customer_id | cust_name | city | grade | salesman_id
-------------+----------------+------------+-------+-----------
--
3002 | Nick Rimando | New York | 100 |
5001
3007 | Brad Davis | New York | 200 |
5001
3005 | Graham Zusi | California | 200 |
5002
3008 | Julian Green | London | 300 |
5002
3004 | Fabian Johnson | Paris | 300 |
5006
3009 | Geoff Cameron | Berlin | 100 |
5003
3003 | Jozy Altidor | Moscow | 200 |
5007
3001 | Brad Guzan | London | |
5005

Sample table: orders


ord_no purch_amt ord_date customer_id salesman_id
---------- ---------- ---------- ----------- -----------
70001 150.5 2012-10-05 3005 5002
70009 270.65 2012-09-10 3001 5005

MS. KAJAL PATIL 10


70002 65.26 2012-10-05 3002 5001
70004 110.5 2012-08-17 3009 5003
70007 948.5 2012-09-10 3005 5002
70005 2400.6 2012-07-27 3007 5001
70008 5760 2012-09-10 3002 5001
70010 1983.43 2012-10-10 3004 5006
70003 2480.4 2012-10-10 3009 5003
70012 250.45 2012-06-27 3008 5002
70011 75.29 2012-08-17 3003 5007
70013 3045.6 2012-04-25 3002 5001

Sample table: customer

customer_id | cust_name | city | grade | salesman_id


-------------+----------------+------------+-------+-----------
--
3002 | Nick Rimando | New York | 100 |
5001
3007 | Brad Davis | New York | 200 |
5001
3005 | Graham Zusi | California | 200 |
5002
3008 | Julian Green | London | 300 |
5002
3004 | Fabian Johnson | Paris | 300 |
5006
3009 | Geoff Cameron | Berlin | 100 |
5003
3003 | Jozy Altidor | Moscow | 200 |
5007
3001 | Brad Guzan | London | |
5005

Perform following operation on the table


1. From the following tables write a query to find the salesperson and customer who reside in
the same city. Return Salesman, cust_name and city.
2. From the following tables write a query to find those orders where the order amount exists
between 500 and 2000. Return ord_no, purch_amt, cust_name, and city name.
3. From the following tables write a query to find the salesperson(s) and the customer(s) he
represents. Return Customer Name, city, Salesman, commission.
4. From the following tables write a query to find salespeople who received commissions of
more than 12 percent from the company. Return Customer Name, customer city, Salesman,
commission.
5. From the following tables write a SQL query to locate those salespeople who do not live in the
same city where their customers live and have received a commission of more than 12% from
the company. Return Customer Name, customer city, Salesman, salesman city, commission.
6. From the following tables write a query to find the details of an order. Return ord_no,
ord_date, purch_amt, Customer Name, grade, Salesman, commission.
7. Write a SQL statement to join the table’s salesman, customer and orders so that the same
column of each table appears once and only the relational rows are returned.

MS. KAJAL PATIL 11


8. From the following tables write a query to display the customer name, customer city, grade,
salesman, salesman city. The results should be sorted by ascending customer_id.
9. From the following tables write a query to find those customers with a grade less than 300.
Return cust_name, customer city, grade, Salesman, salesmancity. The result should be
ordered by ascending customer_id.
10. Write a SQL statement to make a report with customer name, city, order number, order date,
and order amount in ascending order according to the order date to determine whether any
of the existing customers have placed an order or not.
11. Write a statement to generate a list in ascending order of salespersons who work either for
one or more customers or have not yet joined any of the customers.
12. From the following tables write a SQL query to list all salespersons along with customer name,
city, grade, order number, date, and amount.
13. Write a statement to make a list for the salesmen who either work for one or more customers
or yet to join any of the customer. The customer may have placed, either one or more orders
on or above order amount 2000 and must have a grade, or he may not have placed any order
to the associated supplier.
14. For those customers from the existing list who put one or more orders, or which orders have
been placed by the customer who is not on the list, create a report containing the customer
name, city, order number, order date, and purchase amount
15. Write a statement to generate a report with the customer name, city, order no. order date,
purchase amount for only those customers on the list who must have a grade and placed one
or more orders or which order(s) have been placed by the customer who neither is on the list
nor has a grade.
16. Write a query to combine each row of the salesman table with each row of the customer
table.
17. Write a statement to create a Cartesian product between salesperson and customer, i.e. each
salesperson will appear for all customers and vice versa for that salesperson who belongs to
that city.
18. Write a statement to create a Cartesian product between salesperson and customer, i.e. each
salesperson will appear for every customer and vice versa for those salesmen who belong to a
city and customers who require a grade
19. Write a statement to make a Cartesian product between salesman and customer i.e. each
salesman will appear for all customers and vice versa for those salesmen who must belong to
a city which is not the same as his customer and the customers should have their own grade.

MS. KAJAL PATIL 12

You might also like