0% found this document useful (0 votes)
44 views

MYSQL Assignments

Class 12th Practice assignments for students on topic Mysql

Uploaded by

kiana.gupta302
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

MYSQL Assignments

Class 12th Practice assignments for students on topic Mysql

Uploaded by

kiana.gupta302
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Class XII Computer Science (083) Practical

Assignment -1
SQL Commands)

Q-1 Write SQL Command for (a) to (o) and output of (p)
TABLE : GRADUATE
S.NO NAME STIPEND SUBJECT AVERAGE DIVISION

1 KARAN 400 PHYSICS 68 I

2 DIWAKAR 450 COMP Sc 68 I

3 DIVYA 300 CHEMISTRY 62 I

4 REKHA 350 PHYSICS 63 I

5 ARJUN 500 MATHS 70 I

6 SABINA 400 CHEMISTRY 55 II

7 JOHN 250 PHYSICS 64 I

8 ROBERT 450 MATHS 68 I

9 RUBINA 500 COMP Sc 62 I

10 VIKAS 400 MATHS 57 II

a. Create Database DB1 and Create Table Graduate in DB1 database.

b. Insert 10 rows in Graduate table.


c. List the names of those students who have obtained DIV I.

d. Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend


received in a year assuming that the STIPEND is paid every month.

e. To display students details who are studying maths.

f. To insert a new 11th row in the GRADUATE table:(11,”KAJOL”, 300, “Comp Sc”,
75, 1)x

g. Add a new column GRADE of character type.

h. Display Name and division only in Graduate table.


i. To display students details sorted by NAME.

j. To display students details sorted by NAME in descending order.

k. To display student’s details whose average is between 50 to 60.


l. Display student RUBINA’s details.

m. Delete KAJOL’s details from table.

n. To display students details who are either PHYSICS or COMPUTER SC


graduates.

o. Give the output of following sql statement based on table GRADUATE:


(i) Select * from GRADUATE where SUBJECT=”PHYSICS”;

(ii) Select Name, Average from GRADUATE WHERE div=2;


(iii) Select from Name, , Average from GRADUATE where AVERAGE>=65;

(iv) Select distinct SUBJECT from GRADUATE;

Class XII Computer Science (083)


Practical Assignment -2 (SQL Commands)
1. Consider a database LOANS with the following table:
Table: Loan_Accounts
AccN Cust_Name Loan_Amount Instalments Int_Rat Start_Date Interes
o e t
1 R. K. Gupta 300000 36 12.00 19-07-
2009
2 S. P. 500000 48 10.00 22-03-
Sharma 2008
3 K. P. Jain 300000 36 NULL 08-03-
2007
4 M. P. Yadav 800000 60 10.00 06-12-
2008
5 S. P. Sinha 200000 36 12.50 03-01-
2010
6 P. Sharma 700000 60 12.50 05-06-
2008
7 K. S. Dhall 500000 48 NULL 05-03-
2008

Write SQL commands for the tasks 1 to 35


Create Database and use it
1. Create the database LOANS.
2. Use the database LOANS.

Create Table / Insert Into


3. Create the table Loan_Accounts and insert tuples in it.
4. Simple Select
Display the details of all the loans.
5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.

Conditional Select using Where Clause


6. Display the details of all the loans with less than 40 instalments.
7. Display the AccNo and Loan_Amount of all the loans started before 01-
04-2009.

8. Display the Int_Rate of all the loans started after 01-04-2009.

Using NULL
9. Display the details of all the loans whose rate of interest is NULL.

10. Display the details of all the loans whose rate of interest is not NULL.
Using DISTINCT Clause
11. Display the amounts of various loans from the table
Loan_Accounts. A loan amount should appear only once.

12. Display the number of instalments of various loans from the


table Loan_Accounts. An instalment should appear only once.

Using Logical Operators (NOT, AND, OR)


13. Display the details of all the loans started after 31-12-2008
for which the number of instalments are more than 36.

14. Display the Cust_Name and Loan_Amount for all the loans
which do not have number of instalments 36.
15. Display the Cust_Name and Loan_Amount for all the loans for
which the loan amount is less than 500000 or int_rate is more than 12.

16. Display the details of all the loans which started in the year 2009.

17. Display the details of all the loans whose Loan_Amount is in


the range 400000 to 500000.

18. Display the details of all the loans whose rate of interest is in the range 11%
to 12%.
Using IN Operator
19. Display the Cust_Name and Loan_Amount for all the loans for
which the number of instalments are 24, 36, or 48. (Using IN
operator)

Using BETWEEN Operator


20. Display the details of all the loans whose Loan_Amount is in the
range 400000 to 500000. (Using BETWEEN operator)

21. Display the details of all the loans whose rate of interest is
in the range 11% to 12%. (Using BETWEEN operator)

Using LIKE Operator


22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans
for which the Cust_Name ends with 'Sharma'.

23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans
for which the Cust_Name ends with 'a'.

24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans
for which the Cust_Name contains 'a'

25. Display the AccNo, Cust_Name, and Loan_Amount for all the loans
for which the Cust_Name does not contain 'P'.

26. Display the AccNo, Cust_Name, and Loan_Amount for all the loans
for which the Cust_Name contains 'a' as the second last character.

Using ORDER BY clause


27. Display the details of all the loans in the ascending order of their
Loan_Amount.

28. Display the details of all the loans in the descending order of their
Start_Date.

29. Display the details of all the loans in the ascending order
of their Loan_Amount and within Loan_Amount in the
descending order of their Start_Date.

Using UPDATE, DELETE, ALTER TABLE


30. Put the interest rate 11.50% for all the loans for which interest rate is
NULL
.

31. Increase the interest rate by 0.5% for all the loans for which
the loan amount is more than 400000.

32. For each loan compute Interest as


(Loan_Amount*(Int_Rate/100)*Instalments).

33. Delete the records of all the loans whose start date is before 2007.
34. Delete the records of all the loans of 'K.P. Jain'

35. Add another column Category of type CHAR(1) in the Loan table.

Class XII Computer Science (083)


Practical Assignment -3 (SQL Commands)
Q1. Create Database Work and activate it.
Table:Worker
EMPN ENAME JOB HIREDAT SAL COM DEPTN
O E M O
8369 SMITH CLERK 1990-12-18 800 NULL 20
0
8499 ANYA SALESMA 1991-02-20 160 500 30
N 00
8521 MAHADEVA SALESMA 1991-02-22 100 300 30
N N 00
8566 MOMIN MANAGE 1991-04-02 250 NULL 10
R 00
8654 BINA ANALYST 1992-12-09 300 NULL 20
00
8698 SHIAVNSH PRESIDEN 1991-11-18 500 NULL 10
T 00
8882 SCOTT SALESMA 1991-05-01 120 1200 30
N 00

2. Create the table WORKER and add records as shown below. Write
SQL commands for the statements (a) to (g).
a. To display the details in ascending order of salary.

b. To display empno, empname in descending order of hiredate.

c. To display the details in ascending order of empno.


d. To display the sum of salary with heading ‘Sum of salary’.

e. To display the number of employees in each department


number.

f. To display the number of employees in each department but


number of employees should be less than 3.

g. To display the sum of salary, average of salary, maximum and


minimum salary of each job title.
3. Create a table EMPLOYEE with the following data in Work database. Write
SQL commands for the statements (a) to (h).
Table: EMPLOYEE

No Name Salar Area Age Gr Dept


y a
d

e
711 KESHAR 40000 WEST 45 C CIVIL
262 KIRTI 35000 SOUTH 38 A ELEC
693 KRIPPLE 60000 NORTH 52 B CIVIL
724 ARYAN 38000 NORTH 29 B CIVIL
705 SAMSON 42000 EAST 35 A COMP
606 BISWAL 29000 SOUTH 34 A MECH
a. To display the list of all employees in ascending order of salary.
b. To display the employee names in descending order of age.

c. To display the grade and number of employees in each grade.

d. To display the area and number of employees in each area.

e. To display the sum and average salary of the employees of


grade ‘B’.

f. To display grade and maximum, minimum and average salary


of each grade.

g. To display the sum, average, maximum and minimum of salary.

h. To display grade and the number of employees in each


grade where the number of employees are more than
two..
Class XII Computer Science (083)
Practical Assignment -4 (SQL Joins)

4. Create Database Cust and create two tables HANDSETS and


CUSTOMER in it as given below:
Customer
Handsets CustN SetN CustAddre
o o ss
SetCo SetName TouchScre Pho Cost 1 N2 Delhi
de en ne
N1 Nokia 2G N 500 2 B1 Mumbai
0 3 N2 Mumbai
N2 Nokia 3G Y 800 4 N1 Kolkata
0 5 B1 Delhi
B1 BlackBer 2G N 140
ry 00

With reference to these tables, Write commands in SQL for (a) and (b) and
output for (c) below:
a. Display the CustNo, CustAddress and corresponding SetName for each
customer.

b. Display the Customer Details for each customer who uses a Nokia handset.

c. select SetNo, SetName from Handsets,


customer where SetNo = SetCode and
CustAddress = 'Delhi';
5. Create the following tables SENDER and RECIPIENT in Cust database. Write SQL
commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
Table: SENDER
SenderI SenderNam SenderAddress SenderCit
D e y
ND01 R Jain 2, ABC Appts New Delhi
MU02 H Sinha 12, Newtown Mumbai
MU15 S Jha 27/A, Park Street New Delhi
ND50 T Prasad 122 K, SDA Mumbai
Table: RECIPIENT
RecID SenderI RecName RecAddress RecCity
I D
K005 ND01 R Bajpayee 5, Central Kolkata
Avenue
ND08 MU02 S mahajan 116, A Vihar New
Delhi
MU19 ND01 H Singh 2A, Andheri Mumbai
East
MU32 MU15 P K Swamy B5, C S Mumbai
Terminus
ND48 ND50 S Tripathi 13, Mayur Vihar New
Delhi
a. Display the names of all senders from MUMBAI.

b. Display the RecID, SenderName, SenderAddress, RecName,


RecAddress for every recipient.
c. Display the recipient details in ascending order of RecName.

d. Display the number of recipients in each city.

GIVE OUTPUTS
e. SELECT DISTINCT SenderCity FROM sender;

f. SELECT A.SenderName, B.RecName FROM Sender A,


Recipient B
WHERE A.SenderID = B. SenderID AND B.RecCity = ‘Mumbai’;
g. SELECT RecName, RecAddress
FROM Recipient WHERE
RecCity NOT IN
(‘Mumbai’,’Kolkata’);

h. SELECT RecID, RecName FROM Recipient


WHERE SenderID = ‘MU02’ OR SenderID = ‘ND50’;
Class XII Computer Science (083)
Practical Assignment -5 (SQL Joins)
Q6(I).Create the following tables PRODUCT and CLIENT. Write SQL commands for the statements
(a) to (d) and give outputs for SQL queries (e) to (h)
Table: PRODUCT
P_ID ProductNam Manufacturer Price
Table: CLIENT e
TP0 Talcom LAK 40
C_I ClientName City P_ID 1 Powder
D FW Face Wash ABC 45
1 Cosmetic Shop Delhi FW05 05
BS0 Bath Soap ABC 55
6 Total Health Mumbai BS01 1
SH0 Shampoo XYZ 120
12 Live Life Delhi SH06 6
15 Pretty One Delhi FW12 FW Face Wash XYZ 95
12
16 Dreams Bangalore TP01

a. To display the details of those clients whose city is Delhi.


b. To display the details of the products whose price is in the range 50 to 100
(Both values included).

c. To display the ClientName, City from table Client, and ProductName and
Price from table Product, with their corresponding matching P_ID.

d. To increase the price of all products by 10.

e. SELECT DISTINCT City FROM Client;


f. SELECT Manufacturer , MAX(price) , MIN(Price), COUNT(*)FROM
Product GROUP BY Manufacturer;

g. SELECT ClientName , Manufacturer FROM Product P, Client C WHERE


C.P_ID = P.P_ID;

h. SELECT ProductName, Price * 4 FROM Product;WHERE P_ID = ‘TP01’ OR


P_ID = ‘SH06’;

6. (II) Create the following tables WORKER and PAYLEVEL. Write SQL
commands for the statements (a) to (d) and give outputs for SQL queries
(e) to (h)
Table: WORKER
EC NA DESIG PLE D D
O ME V O O
D E J B
E L
11 Radhe Shyam Supervisor P001 13-Sep-2004 23-Aug-
1981
12 Chander Nath Operator P003 22-Feb-2010 12-Jul-1987
13 Fizza Operator P003 14-Jun-2009 14-Oct-1983
15 Ameen Ahmed Mechanic P002 21-Aug-2006 13-Mar-
1984
18 Sanya Clerk P002 19-Dec-2005 09-Jun-1983

Table: PAYLEVEL
PLEVE PA ALLOW
L Y AN
CE
P001 260 12000
00
P002 220 10000
00
P003 120 6000
00

a. To display the details of all WORKERs in descending order of DOB.

b. To display NAME and DESIG of those WORKERs, whose PLEVEL is


either P001 or P002.

c. To display the content of all the WORKERs, whose DOB is in


between ’19-JAN- 1984’ and ’18-JAN-1987’.
d. To add a new row with the following:
19, ‘Daya Kishore’, ‘Operator’, ‘P003’, ’19-Jun-2008’, ’11-Jul-1984’

e. SELECT COUNT(PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;

f. SELECT MAX(DOB), MIN(DOJ) FROM WORKER;

g. SELECT Name, Pay FROM WORKER W,


PAYLEVEL P WHERE W.PLEVEL = P. PLEVEL
AND W..ECODE < 13;\

h. SELECT PLEVEL, PAY + ALLOWANCE FROM


PAYLEVEL WHERE PLEVEL = ‘P003’;

Class XII Computer Science (083)


Practical Assignment -6
(Python-MySQL Connectivity)
Integrate SQL with Python by importing
MySQLdb/mysql.connector
1. Create a table Student in a database ‘project’ as shown below:
RollNo int primary key
Name varchar(20)
Total int
Grade varchar(3)
a. Input Rollno, Name, Total marks and Grade and insert the record in a table
Student.
OUTPUT—

b. Input Rollno and update the corresponding record in a table


Student with the value entered by the user.

OUTPUT—-----------
c. Display all the records from a table Student.

OUTPUT—------

2. Consider the table Product with following structure.


P_ID | ProductName | Manufacturer | Price

1 | Laptop | Dell | 1000.0


2 | Phone | Apple | 800.0
3 | Tablet | Samsung | 600.0

Write Python code to increase the price of all products by 50.

3. Create a table Student in a database ‘project’ as shown below:


RollNo int primary key
Name varchar(20)
Total int
Grade varchar(3)
a. Input Rollno and display the corresponding information from the table
Student.

OUTPUT—------
b. Input Rollno and delete the corresponding record from the table
Student.

OUTPUT—------

c. Display all the records of a grade entered by the user from the table
Student.

OUTPUT—------

d. Display all the records in descending order of total marks from the table
Student.

OUTPUT—-----

You might also like