We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
PRACTICAL FILE 2023-24
CLASS XII- COMPUTER SCIENCE (PART II - MYSQL)
MANISH KUMAR GUPTA
Consider the following table Teacher PGT CS, KV No. 2 SAGAR
TABLE : TEACHER
TID Tname | Tage | Subject | Type | Exp | Grade
1001 | Ashok 25 [Hindi Senior 5 3000
1002 | Kamal 27 | English Junior | NULL | 3000
1003 | Vikas 32__| Hindi Senior 3 2500
1004 [Aman 18 | Physies Senior 7 2800
1005 | Yogesh 32__| Maths Senior | NULL | 3200
1006 _ | Mayank 31 Computer| Junior 4 4000
1007 | Ajay 27__| English Junior | NULL | 3500
1008_[ Anshuman [21 | Physics Senior 2 2800)
1009 | Shashank 19 [Computer| “Senior _[ NULL | 7000
1010 | Mahak 24 | Hindi Junior 3 3000
QUERIES
1. Write a query to create database school.
Create database school;
2, Write a query to see the available databases.
Show databases;
3. Write a query to access database school.
Use school;
4, Write a query to see available tables
Show tables;
5. Write a query to create the above table Teacher.
Create table teacher(tid integer, Tname varchar(15), tage integer, subject varchar(12), type
varchar(10), exp integer, grade integer);
6. Write a query to see the structure of table Teacher
DESC teacher;
DESCRIBE teacher;
7. Write a query to insert above data/row to the table.
Insert into teacher values(1001, ‘Ashok’, 25, 'Hindi, ‘Senior’, 5, 5000);
Insert into teacher values(1002, ‘Kamal’, 27, ‘English’, ‘Junior’, NULL, 3000);
Insert into teacher values(1003, ‘Vikas’, 32, 'Hindi’, Senior’, 3, 2500);
Insert into teacher values(1004, ‘Aman’, 18, Physics’, "Senior", 7, 2800);
Insert into teacher values(1005, 'Yogesh’, 32, 'Maths’, ‘Senior’, NULL, 3200);
Insert into teacher values(1006, ‘Mayank’, 31, ‘Computer’, Junior’, 4, 4000);
Insert into teacher values(1007, ‘Ajay’, 27, 'English’, ‘Junior’, NULL, 5500);
Insert into teacher values(1008, ‘Ayushman’, 21, ‘Physics’, ‘Senior’, 2, 2800);
Insert into teacher values(1009, ‘Shashank’, 19, ‘Computer’, ‘Senior’, NULL, 7000);
Insert into teacher values(1010, ‘Mahak’, 24, 'Hindi’, ‘junior’, 3, 3000);8 Write a query to see the content of table Teacher
Select * from teacher;
9. Write a query to display teacher name, salary from table teacher
Select tname, grade from teacher;
10. Write a query to display teacher name, his subject and his experience from table
teacher.
Select tname, subject, exp from teacher;
11. Write a query to display the various subject names in table teacher
Select distinct(subject) from teacher;
Select distinct subject from teacher;
12. Write a query to display all teacher with experience
Select * from teacher where exp is not NULL;
13. Write a query to display all teacher with null experience.
Select * from teacher where exp is NULL;
14. Write a query to display all teacher with age 30 or less.
Select * from teacher where tage<=30;
15. Write a query to display detail
Select * from teacher where TI
of teacher whose teacher id is 1007 from table teacher.
1007;
16. Write a query to display details of teacher Mayank from table teacher.
Select * from teacher where Tname = ‘Mayank’;
17. Write a query to display tname, grade, subject of Hindi teacher from table teacher.
Select tname, grade, subject from teacher where subject = ‘Hindi’;
18. Write a query to display teacher name, his age, type for all Junior teacher from table
teacher
Select tname, tage, type from teacher where type = ‘Junior’;
19. Write a query to display all det
Select * from teacher where subject
of Computer teachers
‘Computer’;
20. Write a query to display details of teacher having age from 22 to 28.
Select * from teacher where tage between 22 and 28
21. Write a query to display teacher name, age, type and subject for Hindi, English and
physics teacher from table teacher.
Select tname, tage, type, subject from teacher where subject in(‘Hindi’, ‘English’, ‘Physics’
22. Write a query to display of senior teacher teaching English subject from table teacher.
Select * from teacher where Subject = ‘English’ and type = ‘Senior’;
23, Write a query to display teacher arranged in order of grade.
Select * from teacher order by grade;24, Write a query to display tname, age, subject and grade from table teacher in the order
of age in descending order.
Select tname, tage, subject, grade from teacher order by tage desc;
25. Write a query to display teacher name, subject, experience, age, type and grade from
table teacher for all senior teacher arranged in descending order of their age.
Select tname, subject, exp, tage, type, grade from teacher where type = ‘Senior’ order by tage
dese;
26.Write a query to display Teacher id, teacher name, subject and type for all teachers
name starting from letter A from table teacher.
Select tid, tname, subject, exp, tage, type, from teacher where tname like ‘A%';
27.Write a query to display teacher name, their age and subject of teacher name with
name ending with letter ‘k’ in ascending order of their age from table teacher.
Select tname, tage, subject from teacher where tname like ‘%6k’ order by tage;
28, Write a query to display details of teacher name with character ‘n’ in his name from
table teacher.
Select * from teacher where tname like ‘%n%’;
29, Write a query to display teacher name, their age and grade of teacher with heading of
grade as "SALARY’ from table teacher.
Select tname, tage, grade as “Salary” from teacher;
30, Write a query to display tname, Subject and Experience from table teacher, but in
place of null in Experience, column, “NO EXP" should be displayed.
Select tname, subject, ifnull(exp, "No Experience”) from teacher;
31. Write a query to display tname, subject and experience of junior teacher, from table
teacher and New should be displayed if teacher has no experience.
Select tname, subject, ifnull(exp, "New”) from teacher where type = ‘Junior’;
32, To update all teachers by increasing grade by Rs. 1000
Update teachers set grade = grade + 1000;
33, To update all teachers by decreasing grade by 10%
Update teachers set grade = grade * 0.90 ;
34. To change the teacher name of Kamal with new name Komal
Update teacher set tname = ‘Komal’ where tname = ‘Kamal’;
35. Update age of ashok to 35 years
update teacher set tage = 35 where tname = ‘Ashok’;
36. Update experience of teacher to 7 years for the teacher whose teacher id is 1008.
update teacher set Exp = 7 where Tid=‘1008';
37. Increase experience of all senior teachers by 1 year
update teacher set Exp = Exp + 1 where type = ‘Senior’;
38, Delete the teacher name Ajay from table teacher
Delete from teacher where tname = ‘Ajay’;39, Delete the teacher who is teaching Hindi and age is 24 years.
Delete from teacher where tage = 24 and subject = ‘Hindi’;
40, Delete the teacher whose teacher id is 1002 from table teacher
Delete from teacher where tid = 1002;
41, Delete the teacher if he is junior and no experience
Delete from teacher where exp is null and type ='‘Junior’;
42. Write a query to delete the table teacher
Drop table teacher;
43, Write a query to remove the database school
Drop database teacher;
QUERY OUTPUT
1, Select * from teacher;
mysql> select * from teacher;
| tid | Tname | tage | subject | type | exp | grade |
| 1001 | Ashok | 25 | Hindi | Senior | 5 | 5000 |
| 1002 | Kamal | 27 | English | Junior | NULL | 3000 |
| 1003 | Vikas | 32] Hindi | Senior | 3] 2500 |
| 1004 | Aman | 18 | Physics | Senior | 7 | 2800 |
| 1005 | Yogesh | 32 | Maths | Senior | NULL | 3200 |
| 1006 | Mayank | 31 | Computer | Junior | 4 | 4000 |
| 1007 | Ajay | -27 | English | Junior | NULL | 5500 |
| 1008 | Ayushman | 21 | Physics | Senior | 2 | 2800 |
| 1009 | Shashank | 19 | Computer | Senior | NULL | 7000 |
[1010 | Mahak =| 24 | Hindi | Junior | 3 | 3000 |
2, Select Tname, Subject from Teacher where tid= 1006; +
| Tname | Subject
| Mayank | Computer
from teacher where type = ‘Junior’;
| Subject | Type
|
| English | Junior |
Computer | Junior |
| English | Junior |
[ Hindi | Junior |
e, Exp, Grade from teacher where grade between 2000 and 4200;
TID | type | Exp | Grade
! !
| 1002 | Junior | NULL | 3000 |
| 1003 | Senior | 3 | 2500 |
| 1004 | senior | 7 | 2800 |
| 1005 | Senior | MULL | 3200 |
| 1006 | Junior | 4 | 4000 |
| 1008 | Senior | 2 | 2800 |
| 1018 | Junior | 3 | 3000 |5. select distinct subject from teacher; +
| subject |
[Hindi |
| English |
| Physics |
[Maths |
| Computer |
6. select distinct (type) from teacher;
| Senior |
| union |
nn
#5
7. Select tname, tage from teacher where tname like '%an';
| tname | tage |
Tname
| tage | subject |
| English |
! |
| 1004 | Aman || 18 | Physics | Senior | 7 |
| 1005 | Yogesh | 32 | Maths | Senior | NULL |
| 1007 | Ajay | 27 | English | Junior | NULL |
| | | Physics | 1 21
| tid | Tname | tage | subject | type | exp | grade |
_—
| 1002 | Kamal | 27 | English | Junior | NULL |
| 1010 | Mahak | 24 | Hindi | Junior | 3]
Pi
=
10, select Tid, Tname, Tage, Type from teacher where subject = "Hindi" order by tage;
See ag
| 11d | Tame | Tage | Type |
| 1010 | Mahak | 24 | Junior |
| 1001 | Ashok | 25 | Senior |
| 1003 | Vikas | 32 | Senior |
11, select tid, subject, exp from teacher where exp is nul
NULL |
NULL |
NULL |
MULL |