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

My SQL Project

The document appears to be a practical file submitted by a student named Varuni Agarwal for their Informatics Practices class. It contains an acknowledgement section thanking various individuals for their support and guidance. The bulk of the document consists of 50 questions answered by Varuni regarding SQL commands and functions to manipulate and retrieve data from databases and tables. Each question is numbered and includes the SQL code used to answer it.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
410 views

My SQL Project

The document appears to be a practical file submitted by a student named Varuni Agarwal for their Informatics Practices class. It contains an acknowledgement section thanking various individuals for their support and guidance. The bulk of the document consists of 50 questions answered by Varuni regarding SQL commands and functions to manipulate and retrieve data from databases and tables. Each question is numbered and includes the SQL code used to answer it.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

St.

Anselm’s North City


School, Jaipur

Practical file
Informatics Practices
(Code No. - 065)
Session-2021-22

Submitted To:- Ms. Kavita Kanwar


Submitted By:- Varuni Agarwal
Class:- 12th B
Roll No.:- 53
Term: 2nd
ACKNOWLEDGEMENT

Apart from the effort to me, the success of any project


depends largely on the encouragement and guidelines of many
others. I take this opportunity to express my gratitude to the
people who have been instrumental in the successful
completion of this project.
I express deep sense of gratitude to almighty god for
giving me strength for the successful completion of this
project.
I express my heartfelt gratitude to my parents for constant
encouragement while carrying out this project.
My sincere thanks to Ms. Kavita Kanwar, a guide,
mentor, who critically reviewed my project and helped in
solving each and every problem, occurred during the
implementation of the project.
CERTIFICATE
This is to certify that Varuni Agarwal has success completed
the practical work entitled in the subject Informatics Practices
(065) laid down in the regulations of CBSE for the purpose of
Practical Examination in Class XII to be held in St. Anselm’s
North City School, Jaipur .

INTERNAL EXAMINER EXTERNAL EXAMINER

INDEX
S.N TITLE DATE PAG Teacher’s
o. E
Signature
NO
1 To create a database. 30|12|2021 8

2 To create student table. 30|12|2021 8

3 Insert Details 30|12|202 1 8-9

4 Delete the details 30|12|2021 10

5 Increase marks by 5% 30|12|202 1 10-11

6 To display Data as specified 30|12|2021 11


7 Average of marks 30|12|2021 12

8 To add a new column email 30|12| 12


2021
9 To add the email id 30|12| 1 13-14
2021
10 To display information as specified 30|12|2021 15

11 To display Information as specified 30|12|2021 15


.
12 Descending order 30|12|2021 16

13 Ascending order 30|12|2021


16
14 To display unique column 30|12|2021 17
15 Min, max, sum and average 30|12|2021 17-18

16 To demonstrate power() 30|12|2021 19

17 To demonstrate round. 30|12|2021 19

18 To demonstrate mod function. 30|12|2021 19

19 To demonstrate text function. 30|12|2021 20-23

20 To demonstrate date functions. 30|12|2021 23-25

21 Distinct keyword. 30|22|2021 25

22 Monthname, trim, dayname, 30|12|2021 26-27


instmod

23 Group by 30|12|2021 27

24 Having clause 30|12|2021 28


25 Group by with order by 30|12|2021 28

26 Group by and having clause with 30|12|2021 28


where clause

27 To remove primary key 30|12|2021 29

28 To add primary key 30|12|2021 29

29 To delete a column 30|12|2021 30

30 To increase marks. 30|12|2021 30


31 To change data type 30|12|2021 30

32 To delete a table. 30|12|2021 30

33 Create a table and insert details 30|12|2021 31

34 Create table loan 30|12|2021 32

35 to display details from loan


30|12|2021 34
36 To display the details as specified 30|12|2021 33

37 To display the details as specified 30|12|2021 33

38 To display the distinct loan_amt 30|12|2021 33

39 To display the details as specified 30|12|2021 34

40 To display the details as specified 30|12|2021 34

41 To display the details as specified 30|12|2021 35

42 Ascending order of loan amount 30|12|2021 35

43 Update interest rate from null to 30|12|2021 35


specified

44 To display the details as specified 30|12|2021 36

45 To delete the details as specified 30|12|2021 36

46 To add a column of data type 30|12|2021 36


char(1)
47 Maximum loan amount as specified 30|12|2021 36

48 Average instalments. 30|12|2021 37

49 Total loan amount 30|12|2021 37

50 Count the total number of 30|12|2021 37


customers

51 to create table sports and insert 30|12|2021 38


records in it

52 The lowest and the highest class 30|12|2021 38

53 The count of student in each class 30|12|2021 39


54 The number of students 30|12|2021 39

55 Create table with specified data 30|12|2021 39-41

56 Average 30|12|2021 41

57 The count number of item 30|12|2021 41

58 Display details as specified 30|12|2021 42-45

59 Create , insert and display 30|12|2021 46-49

60 Create , insert and display 30|12|2021 49-52

Q.1 To create a database.


Create database school;
Q.2 To create student table with student_id, class, section, gender, name, dob and
marks as attribute where the student_id is primary key.

create table student (sutdent_id int(11) primary key,class


Int(11),section char(1),gender char(1),name varchar(40),dob date,marks
float(10,2));

Q.3 To insert the details of at least 10 students in the above table.

Insert into students values(5,9,’A’,’M’,’Ayush’,’2005-01-02’,60),


(10,9,’C’,’M’,’Bhavesh’,’2005-02-05’,86),
(15,9,’E’,’F’,’Charul’,’2005-03-03’,45)
(20,10,’A’,’M’,’Divyansh’,’2004-11-26’,43),
(25,10,’B’,’F’,’Isha’,’2004-06-23’,63),
(30,10,’C’,’F’,’janvi’,’2004-08-05’,78),
(35,10,’D’,’M’,’Khush’,’2005-07-30’,33),
(40,10,’E’,’F’,’Lavanya’,’2004-09-15’,66),
(45,11,’B’,’M’,’Mohit’,’2003-04-28’,93),
(50,11,’D,,’M’,’Manan’,’2004-12-03’,87),
(55,12,’A’,’F’,’Nikita’,’2003-05-13’,90);
Q.4 To delete the details of a particular student in the above table.
Delete from student where student_id=50;
Q.5 To increase marks by 5% for all those students who have student_id more
than 20.
Update student set marks=marks*1.05 where student_id>20;

Q.6 To display student_id, name and marks of those students who are scoring
more than 50.
Select student_id, name, marks from student where marks>50;
Q.7 To find the average of marks from student table.
Select avg(marks) from student;

Q.8 To add a new column email in above table with appropriate datatypes.
Alter table student add(email varchar(50));
Q.9 To add the email id of each student in the previously created email column.
Update student set email=’ayush05@gmail.com’ where student_id=5;
Update student set email=’bhavesh05@gmail.com’ where student_id=10;
Update student set email=’charul05@gmail.com’ where student_id=15;
Update student set email=’divyansh04gmail.com’ where student_id=20;
Update student set email=’isha04@gmail.com’ where student_id=25;
Update student set email=’janvi04@gmail.com’ where student_id=30;
Update student set email=’khush05@gmail.com’ where student_id=35;
Update student set email=’lavanya04@gmail.com’ where student_id=40;
Update student set email=’mohit03@gmail.com’ where student_id=45;
Update student set email=’nikita03@gmail.com’ where student_id=55;
Q.10 To display the information of all the students whose name starts with
,AN’.
Select * from student where name like ‘AN%’;

Q.11 To display student_id, name,dob of those students who are born between
‘2005-01-01’ and ‘2005-12-31’.
Select Student_id, name, dob from student where dob>’2005-01-01’ and
dob<’2005-12-31’;

Q.12 To display student_id, gender,name,dob in descending order of their


marks.
Select student_id, genderm name, dob from student order by names desc;
Q.13 To display student_id, name, dob, marks, email of those male students in
ascending order of their names.
Select student_id, name, dob, marks, email from student where gender=’M’
order by name;

Q.14 To display the unique section available in the table.


Select student_id from student;
Q.15 Find the min, max, sum and average of the marks in a student marks
table.
1) Minimum
Select min(marks) from student;

2) Maximum
Select max(marks) from student;
3) Sum
Select sum(marks) from student;

4) Average
Select avg(marks) from student;

Q.16 Write a command to demonstrate power()


Select power(5,0);

Q.17 Write a command to demonstrate round.


Select round(1637.3374,-2);
Q.18 Write a command to demonstrate mod function.
Select mod(22,4);

Q.19 Write a command to demonstrate text function.


I) U CASE/UPPER
Select upper(‘aBcdEfg’);

II) L CASE/ LOWERselect lower(‘aBcdEfg’);

III) MID
Select Substr(‘aBcdEfg’,-3);
IV) Length
Select length(‘aBcdEfg’);

V) Leftselect left (‘aBcdEfg’,3);

VI) Right
Select right(‘aBcdEfg’,4);

VII) INSTR()
Select instr(‘aBcdEfg’,’c’);
VIII) LTTIM
Select ltrim(‘ aBcdEfg ‘);

IX) RTRIM
select Rtrim (‘ aBcdEfg ‘);

X) TRIM
select trim( leadimg ’a’ from ‘aBcdEfg’);

Q.20 Write a command to demonstrate date functions.


i) Now()Select
Now();

ii) Date()select date


(now());

iii) MonthSelect
month(now());

iv) Monthname()select
monthname(now())
;
v) year()select
year(now());

vi) Day
Select day(‘2021-07-10’);

vii) Daynameselect
dayname(‘2021-
07-10’);

Q.21) Write a command using distinct keyword.


Select distinct email from student;

Q.22) Write a SQL function which will perform the following operations.
i) To display the the name of the month of the current date. Select
monthname(now());

ii)To remove spaces from the beginning and end of a string


(‘ panorama ‘) select trim(‘
Panorama ‘);
iii)To display the name of the day (eg friday or saturday) from your date of
birth, dob.
Select dayname(‘2003-08-05’);

iv)select instr(‘name’,’fname’);

v)To compute the remainder of divisionbetween two numbers n1 and n2.


Select mod(n1,n2);

Q.23) Write a command using group by.


select count(class),name from student group by name;
Q.24) write a command using having clause.
select avg(marks), class from student group by class having avg(marks)>68;

Q.25) Write a command for using group by with order by. select distinct(class),
section from student group by class order by section;

Q. 26)Command for using group by and having clause with where clause.
Select avg(marks), class from student where gender="M" group by class
having avg(marks)>68;
Q.27) Write a command to remove primary key.Alter table
student drop primary key;

Q.28) Write a command for adding a primary key.


Alter table student add primary key(student_id);
Q. 29)Write a command to delete a column.
Alter table student drop email;

Q.30) Write a command to increase marks.


Update student set marks=marks+10;

Q.31) Write a command to change data type of an existing column.


Alter table student modify marks decimal(8,2);

Q.32) Write a command to delete a table.


Drop table sports;

Q.33) Create a table Product and insert records in it.


Create table Product (product_no Int(11) primary key, product name
varchar(60) not null, DOP Date, company varchar(50), price float(10,3), Qnty
varchar(30);

insert into product values(101,“Router”,“2003-02-23”,”Airtel”, 3349.99,100),


(102, “Switch”, “2000-09-22”,”Anchor”,3499.00, 50),
(103, “RAM”, “2004-08-21”,”RTX”, 4000.50, 60),
(104, “Webcam”, “2002-07-20”,”Sony”,2199.609,20),
(105,“Memory card”,“2004-07-03”,”Sandisk”,300.00,20),
Insert into product (product_no,Product_name,DOP)
values(106,”HeadPhone”,”2004-05-18”),
(107, “Bluetooth Headset”, “2003-04-17”,”Realme”,1999.50,10),
(108, “Speaker”, “2002-03-16”,”JBL”, 1659.99,25);
Q.34) Create table loan with acc_no. acc_name, loan_amt, instal, int_rate,
start_date.
Create table loan( acc_no int(11) primary key. acc_name varchar(50),
loan_amt int(11), instal int(11), int_rate int(11), start_date date;

insert into loan(acc_no, acc_name, loan_amt , instal, start_date)


values(101,”Vishal”, 300000, 36,”2007-09-01”); insert into loan
values(102, “Sharma”, 300000, 40, 12, “2007-05-11”),
(103, “Navya”,200000, 24, 12, “2009-08-10”),
(104, “Fidha”, 430000, 45, 8, “2008-12-12”),
(105, “tanvya”,500000, 12, 15, “2010-02-07”),
(106, “Ashik”, 380000, 10, 21, “2006-03-08”);
Q.35) Write a command to display the account number, customer name and
loan amount of all loans.
Select acc_no , acc_name, loan_amt from loan;

Q.36) Write a command to display the deatails of all loans with less than 40
installments.
Select * from loan where instal<40;

Q.37) Write a command to display the details of all the loan whose rate of
interest is null.
Select * from loan where int_rate is null;

Q.38) Write a command to display the amount of various loans from the table
loans, a loan amount should only appear once.
Select distinct(loan_amt)from loan;

Q.39) Write a command to display the customer name, loan amount for all the
loans which do not have number of instalments 36.
Select acc_name, loan_amt from loan where instal!=36;

Q.40) Write a command the details of all the loans whose loan amount is in the
rate of 400000 and 500000.
Select * from loan where loan_amt between 400000 and 500000;
Q.41) Write a command to display the account number, customer name and
loan amount of all the loans for which customer name is “sharma”.
Select acc_no, acc_name, loan_amt from loan where acc_name like
“%sharma%”;

Q.42) Write a command to display the details of all loans in the ascending
order of their loan amount
Select * from loan order by loan_amt desc;

Q.43) Write a command to put the interest rate 11.50% for all the loans for
which the interest rate is null.
Update loan set int_rate=11.50 where int_rate is null;
Q.44) Display the details of all the loans whose instalment is below 40 and
loan amont above 250000.
Select * from loan where instal<40 and loan_amt >250000;

Q.45) Write a command to delete the details of all loans whose start date is
before 2008
Delete from loan where year(start_date)<2008;

Q.46) Write a command to add a column category of type char(1) in the table
loan.
Alter table loan add category char(1);

Q.47) Display the maximum loan amount whose interest rate is 12%.
Select max(loan_amt) from loan where int_rate=12;
Q.48) Find the average instalments.
Select avg(instal) from loan;

Q. 49)Find the total loan amount.


Select sum(loan_amt) from loan;

Q.50) To count the total number of customers whose loan started after
2008.
Select count(start_date) from loan where year(start_date)>2008;
Q.51) Write a command to create given table sports and insert records in
it.
Create table sports( adm_no Int(11) primary key, game varchar(50),
coach_name varchar(60), Grade char(1));

insert into sports values(111,”Cricket”, “Seerja”,”A”),


values(112,”football”, “Vaibhav”,”A”),
values(113,”football”, “Dhwani”,”A”),
values(114,”badminton”, “Farzana”,”B”),
values(115,”hockey”, “Karan”,”B”), values(116,”Cricket”,
“Ablin”,”B”);

Q.52) Display the lowest and the highest class from the table student.
Select Min(class),Max(class) from student;

Q. 53)Display the number of students in each class from the table student.
Select count(class), class from student group by class;
Q.54) Display the number of students with each coach.
Select count(*), coach name from sports group by coach_name;

Q.55) Create table item and bill and insert the given records in it.
Create table item(icode int(11) primary key, name varchar(50), category
varchar(60), rate int(11));

Insert into item values(1001, “ghee roast”,”South Indian”,60),


(1002, “vada sambar”,”South Indian”,40),
(1003, “upma”,”South Indian”,30),
(1004, “noodles”,”Chinese”,100),
(2001, “soup”,”Chinese”,80),
(3001, ”pizza”,”Italian”,120),
(3002, “pasta”,”Italian”,125);

Create table bill(bill_no int(11) primary key, date Date, icode int(11) , quantity
int(11));

insert into bill values(1,”2010-04-01”,1002,2),


(2,”2010-05-01”,1003,3),
(3,”2010-06-01”,1004,1),
(4,”2010-07-01”,1005,2),
(5,”2010-08-01”,1006,4),
(6,”2010-09-01”,1007,3),
(7,”2010-10-01”,1001,2);

Q.56) Display the average rate of South Indian item.


Select avg(rate) from item where category=”South Indian”;
Q.57) Display the number of item in each category; select
count(*),category from item group by category;

Q.58) Consider the following table given below and answer the following
questions.
No Name Salary Zone Age Grade Dept
.
1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
3 Naveen 32000 West 40 NULL 20
4 Uday 38000 North 38 C 30

5 Nupur 32000 East 26 NULL 20


6 Moksh 37000 South 28 B 10
7 Shelly 36000 North 26 A 30
Create table Employee(no Int(11) primary key, name varchar(50), salary
int(11), Age int(11), Grade char(1), dept int(11));
Insert into employee values(1,”Mukesh”,30000,”West”,28,”A”,10);
Insert into employee values(2,”Kritika”,35000,”Centre”,30,”A”,10);
Insert into employee(No, Name, Salary, Zone, Age, Dept)
values(3,”Naveen”,32000,”West”,40,20);
Insert into employee values(4,”Uday”,38000,”North”,38,”A”,30);
Insert into employee(No, Name, Salary, Zone, Age, Dept)
values(5,”Nupur”,32000,”East”,26,20);
Insert into employee values(6,”Moksh”,37000,”South”,28,”A”,10);
Insert into employee values(7,”Shelly”,36000,”North”,26,”A”,30);
1) Display the details of all the employees whose grade is null.
Select * from employee where Grade is NULL;

2) Display the details of all the employees who are getting a salary of more
than 35000 in the department 30.
Select * from employee where salary>35000 and dept=30;

3) Display the name and salary of all the employees who are working neither
in west zone nor in center zone.
Select name, salary from employee where zone!= “west” and zone! =“center”;

4) Display the average salary of grade “A” employees.


Select avg(salary) from employee where grade=”A”;
5) Display the total number of employees in each department.
Select count(*),dept from employee group by dept;

6) Display the details of all the employees in the ascending order of their
salaries.
Select * from employee order by salary;

7) Display the name, salary and age of all the employees whose name starts
with “a”.
Select name, salary, age from employee where name like “a%”;

Q.59) Consider the table teacher and answer the following questions.
Create table Teacher( No int(11) primary key, Name Varchar(50),Age int(11),
Department Varchar(40), DATEOFJOIN DATE, Salary decimal(10,2), Sex
Char(1));

insert into teacher values(1,”Jugal”,34,”Computer”,”2000-01-


10”,20000.00,”M”),
(2,”Sharmila”,31,”History”,”2008-03-24”,12000.00,”F”),
(3,”Sandeep”,35,”Maths”,”2006-12-12”,30000.00,”M”),
(4,”Sangeetha”,31,”History”,”2007-07-01”,40000.00,”F”),
(5,”Shyam”,35,”Maths”,”2007-09-05”,25000.00,”M”),
(6,”Rakesh”,31,”History”,”2007-02-25”,30000.00,”M”),
(7,”Shivom”,44,”Computer”,”2008-06-27”,21000.00,”M”),
(8,”Shalaka”,31,”Maths”,”2007-07-31”,20000.00,”F”);

1)
Display the name and salary of male teachers in the math department.
Select name, salary from teacher where sex=”M” and department=”maths”;
2)Display the no of teachers in each department.
Select count(*), department from teacher group by department;

3)Display the details of all teachers who are getting salary less than 25000 of
computer department.
Select * from teacher where salary<25000 and department = “computer”;

4)Display the total salary and the average salary of teachers of history
department.
Select avg(salary), Sum(salary) from teacher where department=”history”;

5)Display the name, age and department of teachers whose name contains H as
the second character.
Select name, age, department from teacher where name like”_h%”;

6) Display the name, department, Salary and Sex of teachers in descending


order of their salary.
Select name, department, salary, sex from teacher order by salary;

7)Display the details of teachers joined in the year 2007.


Select * from teacher where year(DATEOFJOIN)=2007;

Q.60) Consider the table teacher and answer the questions given below.
1) Display the details of female teachers of history department.
Select * from teacher where Sex=”F” and Department=”History”;

2) Display the name and Date of join of teachers according to their date of
join.
Select name, DATEOFJOIN from teacher group by DATEOFJOIN;

3) Display the name and age of male teachers.

Select name, age from teachers where sex=”M”;


4) Display the department and total salary of each department.
Select department, Sum(salary) from teacher group by department;

5) Display the department, minimum and maximum salary of each department.


Select department, max(salary), min(salary) from teacher group by department;

6)Display the details of teachers whose age is in the range 31 to 34.


Select * from teacher where age>=31 and age<=34;
7)Display the details of teachers whose name begins with S.
Select * from teacher where name like ”S%”;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy