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
You are on page 1/ 43
} COMPUTER SCIENCE”
: PRACTICAL PROGRAMS:
FOR GRADE - XI
[2023-2024]
Ir. Appan Raj D M.C.A., B.Ed., - PGT csp:
wrx :‘TABLE OF CONTENTS
‘S.No Name of the Exercises Page.No
Python Programs
1. | Creating a menu driven program to perform arithmetic operations. 3
2. | Creating a python program to display Fibonacci series 5
3. | Creating a menu driven program to find factorial and sum of list ofnumbersusing| 7
function.
4. | Creating a python program to implement returning value(s) from function. 9
5. | Creating a python program to implement mathematical functions. 10
6. | Creating a python program to generate random number between 1 to 6 i
7. | Creating a python program to read a text file line by line and display each word | 12
separated by '#’.
Creating a python program to read a text file and display the number of| 13
vowels/consonants/lower case/ upper case characters.
‘9. | Creating python program to display short words from a text file 15
10. | Creating a python program to copy particular lines of a text file into another text | 16
file.
11. | Creating a python program to create and search records in binary file. 17
12. | Creating a python program to create and update/modify records in binary file. 19
13. | Creating a python program to create and search employee's record in csv file. 21
14. | Creating a python program to implement stack operations (List). 23
15. | Creating a python program to implement stack operations (Dictionary). 26
Python — SQL connectivity programs
16. | Creating a python program to integrate MYSQL with Python (Creating database 28
and table)
17. | Creating a python program to integrate MYSQL with Python (Inserting records | 30
and displaying records)
18. | Creating a python program to integrate MYSQL with Python (Searching and| 32
displaying records)
19. | Creating a python program to integrate MYSQL with Python (Updating records) 33
SQL Queries
20. ] SQL COMMANDS EXERCISE - 1 35
21. | SQL COMMANDS EXERCISE - 2 36
22. | SQL COMMANDS EXERCISE - 3 38
23. | SQL COMMANDS EXERCISE - 4 40
24. | SQL COMMANDS EXERCISE - 5 42
2OPERATIONS
AIM:
To write a menu driven Python Program to perform Arithmetic operations (
based on the user's choice
SOURCE CODE:
print ("1. Adddition™)
lprint("2. Subtraction")
print ("3. Multiplication")
print ("4. Division")
lopt=int(input("Enter your choice:"))
Jasint (input("Enter the First Number:"))
b=int (input ("Enter the Second Number: "))
if opt==1:
c=atb
print ("The Addition of two number is:",c)
Jelif opt=
c=a-b
print("The Subtraction of two number is
Joli opte=s:
c=atb
print ("The Multiplication of two number is:",c)
jeri
print ("Enter any other number other than 0")
else:
cza/b
print ("The Division of two number is:",c)
Jers
print ("Invalid Option")
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
2Python Program Executed Output:
1. Adddition
2. Subtraction
3. Multiplication
4. Division
Enter your choice:1
Enter the First Number:10
Enter the Second Number:23
The Addition of two number is: 33AIM:
‘To write a Python Program to display Fibonacci Series up to ‘n’ numbers.
SOURCE CODE:
fFirst=0
ISecond=1
Ino=int (input ("How many Fibonacci numbers you want to display?"))
lif no<=0:
print("Please Enter Positive Integer")
Jelse:
print (First)
print (Second)
for i in range(2,no):
Third=First+Second
First=Second
Second=Third
print (Third)
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.How many Fibonacci numbers you want to display?8
HPOaUWNHHOAIM:
To write a menu driven Python Program to find Factorial and sum of list of numbers
using function.
SOURCE CODE:
def Factorial (no):
Fel
Af no
RESTART: C:\Users\AP2S \AppData\Local|\Prograns \Python\2ython36\PR COPY_TEXT FILE.py
|All lines which are starting with character 'a' or 'A' has been copied successfully into New. txt|
New.txt:
TB “New Clean APS Mopac rogram yon db News Gar
Aeroplane was invented by the Right Brothers.
lan apple a day keeps the doctor away.
S|DATI
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN
BINARY FILE
AIM:
To write a Python Program to Create a binary file with roll number and name.
Search for a given roll number and display the name, if not found display appropriate
message.
SOURCE CODE:
Inport pickle
ef Create():
Feopen ("Students dat”, 'ab')
ept='y'
while opte='y!
Rol}_Nosint (input ("Enter roll number: '))
Wane=input ("Enter Nane:")
L={Roll_No Nano}
Pickle. dump (1, P)
opt=input ("Do you want to add another student detail (y/n) :")
F.close()
def Search():
Peopen("Students dat", 'zb")
nosint (input ("Enter Rol1.No of student to seazch:"))
found=0
try
while True:
Sepickle. oad F
Sf 8[0]=eno:
print("The searched Roll.No is found and Details are:",$)
found=1
break
xcept:
F.close()
Af found==t
print ("
fain Program
create)
Search ()
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
1SAMPLE OUPUT:
PYTHON PROGRAM EXECUTED OUTPUT:
Enter roll number:1
Enter Name:Arun
Do you want to add another
Enter roll number:2
Enter Name:Bala
Do you want to add another
Enter roll number:3
Enter Name:Charan
Do you want to add another
Enter roll number:4
Enter Name:Dinesh
Do you want to add another
Enter roll number:5
Enter Name:Divya
Do you want to add another
student detail (y/n) :y
student detail (y/n) :y
student detail (y/n) :y
student detail (y/n) :y
student detail(y/n) :n
Enter Roll.No of student to search:3
The searched Roll.No is found and Details are: [3, 'Charan']BINARY FILE
AIM:
To write a Python Program to Create a binary file with roll number, name, mark
and update/modify the mark for a given roll number.
SOURCE CODE:
Snport pickle
der Create()
Paopen ("Marks dat", 'ab")
ept='y’
while optee'y
Roll_Nowint (input ("Enter roll number: '))
Wane=input ("Enter Nana: "
Marksint (input ("Enter Mazks:"))
L=[Roll_No, Name, Mark]
pickle. dump (LF)
optminput ("Do you want to add another student detail (y/n) :")
Peopen ("Marks dat", ‘rb+')
no=int (input ("Enter Student Rol1.No to modify marks:"))
found=0
tey:
while True:
Pos=F. tell ()
Sepickle, load.
if s[0]=no:
PEint ("The searched Roll.No is found and Detaiis are:
S{2}mint (input ("Enter New Mark to be update:"))
F. seek (Pos)
pickle.dump(s,F)
foundel
F. seek (Pos) #moving the file pointer again beginning of the current record.
print ("Mark updated Successfully and Details are:",S)
break
a
F.close()
Af found==0.
Print ("The Searched Roll.No is not found")
main Progran
create ()
Update ()
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
SS |)SAMPLE OUTPUT:
PYTHON PROGRAM EXECUTED OUTPUT:
Enter roll numbe:
Enter Name:Arun
Enter Marks: 450
Do you want to add another
Enter roll numbe:
Enter Name:Bala
Enter Marks: 342
Do you want to add another
Enter roll number:3
Enter Name:Charan
Enter Marks: 423
Do you want to add another
Enter roll numbe:
Enter Name:Dinesh
Enter Marks:356
Do you want to add another
Enter roll number:5
Enter Name:Divya
Enter Marks: 476
Do you want to add another
student detail(y/n) :y
student detail(y/n) :y
student detail (y/n) :y
student detail(y/n) :y
student detail(y/n) :n
Enter Student Roll.No to modify marks:3
The searched Roll.No is found and Details are:
Enter New Mark to be update:470
Mark updated Successfully and Details are: [3,
[3, 'Charan',
‘Charan’, 470]
423]All
To write a Python program Create a CSV file to store Empno, Name, Salary and search any Empno
and display Name, Salary and if not found display appropriate message.
SOURCE CODE:
Tapert cay
def Create():
Feopen("Emp. csv", 'a' ,newline=
Wecsv.writer(F)
opt='y
while optes'y':
Nosint (input ("Enter Employee Number: "))
Namewinput ("Enter Employee Nane:
Salnfloat (input ("Enter Employee Salary:"))
2=[No, Name, Sal]
W.writerow(L)
opt=input ("Do you want to continue (y/n)?:")
F.close()
Jace Search ()
Feopen("Emp.csv", 'r' ,newline="\r\n")
nosint (input ("Enter Employee number to search")
found=0
row=csv. reader (F)
for data in row:
Af data[0]==str(no) :
print ("\nEmployee Deatils are:")
print ("
Print ("Name:" ,data{1])
print ("Salary:",data[2])
")
Af found==0:
Print ("The searched Employee number is not found")
F.close()
Jiuain Program
create)
[Search ()
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
1Enter Employee Number:1
Enter Employee Name:Anand
Enter Employee Salary:23000
Do you want to continue (y/n) ?:y
Enter Employee Number: 2
Enter Employee Name:Akash
Enter Employee Salary:25000
Do you want to continue(y/n)?:y
Enter Employee Number:3
Enter Employee Name:Balu
Enter Employee Salary:27000
Do you want to continue (y/n) ?:y
Enter Employee Number: 4
Enter Employee Name:Bavya
Enter Employee Salary:29000
Do you want to continue (y/n) ?:y
Enter Employee Number:5
Enter Employee Name:Manoj
Enter Employee Salary:35000
Do you want to continue (y/n)?:n
Enter Employee number to search:3
Employee Deatils are:
Name: Balu
Salary: 27000.0
2DATE:
aw
(ii)
ww)
[det Pop):
\def Peele():
\def Disp():
CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(LIST)
To write a Python program to implement Stack using a list data-structure, to perform
the following operations:
(To Push an object containing Doc_ID and Doc_name of doctors who specialize
in "ENT" to the stack.
(ii) To Pop the objects from the stack and display them.
(ii!) To display the elements of the stack (after performing PUSH or POP)
SOURCE CODE:
Pua
Doo ID=int(input{"Enter the Doctor ID:"))
Doc Name=input{'Enter the Name of the Dector:")
tlinput("Eater the Mobile Number of the Doctor:")}
Special=input( ‘Eater the Specialization")
Wf Special=="ENT:
‘Stack.append{[Doc_ID,Doc_Name]}
af Stack==[ ]:
print("Stack is empty")
else:
print{"The deleted doctor detail is:",Stack.pop())
‘if Stack==[ }:
ores ‘is empty")
topslea(Stack}1
print("The top of the stack is:',Stack{top])
if Stack==[ }:
print("Stack is empty")
else:
top=ien(Stack)-1
for i in range(topy-1,-1):
print(Stack{i])ek=[]
‘Performing Stack Operations Using List\n")
le ches'y’ or ch=='Y't
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
Python Program Executed Output:
Performing Stack Operations Using List
Do you want to Perform another operstionly/ a}
use
Disp
Enter the Doctor 2
Enter the Name ofthe Doctor Usha
Enter the Mobile Number ofthe Doctor:8785
Enter the SpecializationsCardio
Do you want to Perform another operation(y/ay
the Mobile Number of Ue Dostor:7854
Enter the Specialisation:ENT
smother operstion(y/ a}
1
De oiankia naiEnter the Doctor ID:
Enter the Name of the Doctor:Rani
Enter the Mobile Number of the Doctor:8778
Enter the Specialization:Anesthesia
Do you want to Perform another operation(y/n}:y
..PUSH
2.POP
S.PEEK
4.Disp
Enter your choice:4
[3, Murali]
(1, ‘arun]
Do you want to Perform another operation(y/n}:y
1.PUSH
2.POP
S.PEEK
‘The top of the stack is: [3, "Murali’]
Do you want to Perform another operation(y/n}:y
1.PUSH
2.POP
S.PEEK
4.Disp
Enter your choice:2
The deleted doctor detail is: [3, ‘Murali’]
Do you want to Perform another operation(y/n}:y_
L.PUSH
21POP
S.PEEK
4.Disp
Enter your choice:
[1, Aran]
Do you want to Perform another operation(y/nj:n
5To Write a program, with separate user-defined functions to perform the following
operations:
(i) To Create a function Push(Stk,D) Where Stack is an empty list and D is Dictionary of Items.
from this Dictionary Push the keys (name of the student) into a stack, where
the corresponding value (marks) is greater than 70.
Gi) To Create a Function Pop(Stk) , where Stk is a Stack implemented by a
names. The function returns the items deleted from the stack.
Gii) To display the elements of the stack (after performing PUSH or POP).
Source Code:
ef PushiSti,Dy
for tin Ds
Le Dis}>70:
Sticappena{i)
oof Popistiey:
este J:
return "Stack is Empty”
etset
print{"The deleted element is:",end="')
Fotura Stie-pep()
t of student
of Dispt:
este
+
print( Stack is empty")
tse
top=ten( Sth
fori in rangettope4y-t}:
print( Stefi)
eney
Det}
see={]
print('Performing Stack Operations Using Dictionary\n')
DiVishat
D[Priya']zint{input{ Enter the Marie of Priya:"))
D[Mano'Jrint{input{"Enter the Mark of Mano:"))
Pash(ste,D)Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
Sample Output:
forming Stack Operations Using Dictionary
inter your choice:1
inter the Mark of Arun:67
enter the Mark of Anu:56
:nter the Mark of Vishal:89
you want to perform another operation(y/n}:nEX.NO: 16
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
{CREATING DATABASE AND TABLE)
AIM:
To write a Python Program to integrate MYSQL with Python to create Database and Table
to store the details of employees.
Source Code:
‘import mysqLeonnector
ot Create DBI:
Con=mysql.connector.connect{host= localhost juser='root jpassword= root)
ty
‘fConis connected\)
cur=Con.cursor{)
(Q='CREATE DATABASE employees"
cur.exeoute(Q)
print Employces database created suceesty’)
excepts
print Database name already exists")
Con.ctose)
of Create Tablet:
Con=mysql.connector.conneet{host= localhost juser= root ,password= root database='employees’)
if Con.is connected):
‘cur=Con.cursor))
(Q="CREATE TABLE EMP(ENO INT PRIMARY KEY,ENAME VARCHAR(20),GENDER VARCHAR(S),SALARY INT)"
cur.exseute(Q)
print("Emp Table created sucessfully")
print{"Table Name already exists")
Con.ctose)
ehey’
while ch=='y' or eh=:
print(’\alnterfacing Python wi
print("1. To Create Database")
print{°2. To Create Table")
optzint{input{"Enter your choice:"))
Mysat")
print{"Tavalid Choice")
opt=input{‘Do you want to perform another operation(y/}:)
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
2Interfacing Python with Mysql
1. To Create Database
2. To Create Table
Enter your choice:1
Employees database created sucessfully
Do you want to perform another operation(y/n):y
Interfacing Python with Mysql
1. To Create Database
2. To Create Table
Enter your choice:2
Emp Table created sucessfully
Do you want to perform another operation(y/n):nEX.NO: 17
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON.
INSERTING RECORDS AND DISPLAYING RECORDS)
AIM:
To write a Python Program to integrate MYSQL with Python by inserting records to
Emp table and display the records
SOURCE CODE:
import mysql. connector
con=aysql connector connect (host='ocalhost',usernane=' root! ,password='root',database='enployees')
if con.is_connected():
cur=con. cursor ()
y't
No=int input("Bnter Employee Number:"))
Nane=input ("Enter Employee Nane:")
Gendersinput ("Enter Employee Gender (M/F)
Salary=int (input "Enter Enployee Salary:"))
Query="INSERT INTO EMP VALUES({},'{}','{)',{})". format (No, Name Gender Salary)
cur.execute (Query)
con, cont ()
print ("Record Stored Successfully")
opt=input ("Do you want to add another employee details(y/n) :")
Query="SELECT * FROM EMP";
car. execute (Query)
datazcur.fetchall |)
for i in data:
print (i)
Result:
Thus, the above Python program has been executed and the output is verified
successfully.
0SAMPLE OUTPUT:
Python Executed Program Output:
Enter
Enter
Enter
Enter
Employee
Employee
Employee
Employee
Number :1
‘Name :Arun
Gender (M/F) :M
Salary:20000
Record Stored Successfully
Do you want to
Enter Employee
Enter Employee
Enter Employee
Enter Employee
add another employee
‘Number :2
Name:Bala
Gender (M/F) :M
Salary:25000
Record Stored Successfully
Do you want to
Enter Employee
Enter Employee
Enter Employee
Enter Employee
add another employee
‘Number: 3
Name:Bavya
Gender (M/F) :F
Salary:27000
Record Stored Successfully
Do you want to
Enter Employee
Enter Employee
Enter Employee
Enter Employee
add another employee
Number: 4
‘Name: Saravanan
Gender (M/F) :M
Salary:29000
Record Stored Successfully
Do you want to
add another employee
(1, ‘Arun', 'M', 20000)
(2, 'Bala', 'M', 25000)
(3, 'Bavya', 'F', 27000)
(4, 'Saravanan', 'M', 29000)
details (y/n) :y
details (y/n):y
details (y/n) :y
details (y/n) :nCREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON,
{SEARCHING AND DISPLAYING RECORDS)
To write a Python Program to integrate MYSQL with Python to search an Employee using,
EMPID and display the record if present in already existing table EMP, if not display the
appropriate message.
SOURCE CODE:
[import mysql connector
\con=ysql .connector connect (host=' localhost! ,usernane=' root ' ,password='root' ,database=' employees’
Lif con.is_connected() :
curscon cursor ()
Print (etasanadaneeenenenenss
Print ("Welcome to Employee Search Screet
Drint ("#tteerenensnensnnnasnnnsnniene
Nosint (input ("Enter the employee nunber to search:"))
Query="SELECT * FROM EMP WHERE EMPID=()". format (No)
cur -execute (Query)
datazcur. fetchone()
AE datal=tone:
print (data)
eu
print ("Record not Found! !!")
icon-close()
Resul
‘Thus, the above Python program has been executed and the output is verified
successfully.
SAMPLE OUTPUT:
Python Executed Program Output:
FESS ISI ISIS ISIS ISS ISS IIo
Welcome to Employee Search Screen
JESSE IOI OSI IOI TOSI II III
Enter the employee number to search:
(2, 'Bala', 'M', 25000)
SSEX.NO: 19.
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(UPDATING RECORDS)
To write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and update the Salary of an employee if present in already existing table
EMP, if not display the appropriate message
SOURCE CODE:
[TaSEE ayaql Connector
icon=mysql.connector. connect (host=! localhost ',sername=' root ' ,password=' root! ,database='enployees"
hie con.is connected) :
Print ("Welcome to Bxployee detail updai
Print ("ssssnectsasasnetensenssneusnesnateneeaet)
Nomint (input ("Enter the employee number to Update:"})
Query="SELECT * PROM EMP WHERE EMPID=(}".format (No)
car. exacute (Query)
datarcur. fetchone ()
Le datatatione:
Print ("Record found details are:")
print (data)
‘ansminput ("Do you vant to update the Salary of the above employee (y/n)
Af ansee'y’ or anse='Y!
‘New Salwint (input ("Enter the New Salary of an Employee:"))
(QLSTUPDATE EMP SET SALARY=(} WHERE EMPID=(}" format (New_S21,Mo)
cur-execute (91)
con. commit ()
Print ("Employee Salary Updated Successfully")
Q2e"SELECT * FROM ENDY
ur sexecute (02)
datazcur.fetchall ()
Sor 4 in data:
print()
else:
print ("Record not Found!!
Result:
‘Thus, the above Python program has been executed and the output is verified
successfully.
ASAMPLE OUTPUT:
hon Executed Program
Welcome to Employee detail update Screen
Enter the employee number to search:
Record found details are:
(3, "BAVYA', 'F', 27000)
Do you want to update the Salary of the above employee (y/n) ?:y
Enter the New Salary of an Employee: 30000
Employee Salary Updated Successfully
(2, ‘Arun’, 'M', 20000)
(2, "Bala', 'M', 25000)
(, "BavyA', "F', 30000)
(, ‘Saravanan', 'M', 29000)SQL COMMANDS EXERCISE - 1
AIM:
‘To write Queries for the following Questions based on the given table:
Rollno | Name | Gender | Age Dept DOA Fees
1 Arun M 24 [COMPUTER| 1997-01-10 |" 120
2 ‘Ankit M 21 [nistory | 1998-03-24 | 200
3 ‘Anu F 20 [HINDI 1996-12-12 | 300
4 Bala M 19 | NULL 1999-07-01 | 400
5 Charan | _M 18___| HINDI 1997-09-05 | 250
6 Deepa F 19 | HisToRY [1997-06-27 |" 300
7 Dinesh | __M 22 [COMPUTER | 1997-02-25 [210
8 Usha F 23 [NULL 1997-07-31 | 200
(a) Write a Query to Create a new database in the name of "STUDENTS".
CREATE DATABASE STUDENTS;
(b) Write a Query to Open the database "STUDENTS".
USE STUDENTS;
(c) Write a Query to create the above table called: "STU"
CREATE TABLE STU(ROLLNO INT PRIMARY KEY,NAME VARCHAR(10),
GENDER VARCHAR(3), AGE INT,DEPT VARCHAR(15),
DOA DATE,FEES INT);
(d) Write a Query to list all the existing database names.
SHOW DATABASES;
(€) Write a Query to List all the tables that exists in the current database
SHOW TABLES;SQL COMMANDS EXERCISE - 2
‘To write Queries for the following Questions based on the given table:
Rollno | Name | Gender | Age Dept DOA Fees
1 Arun M 24 | COMPUTER | 1997-01-10 |~_120
2 ‘Ankit M 21 [nistory | 1998-03-24 | 200
3 ‘Anu F 20 [HINDI 1996-12-12 | 300
4 Bala M 19 | NULL 1999-07-01 | 400
5 Charan | _M 18___| HINDI 1997-09-05 | 250
6 Deepa F 19 | HisToRY [1997-06-27 |" 300
7 Dinesh | __M 22 [COMPUTER | 1997-02-25 [210
8 Usha F 23 [NULL 1997-07-31 | 200
(a) Write a Query to insert all the rows of above table into Info table.
INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);
INSERT INTO STU VALUES (2,'Ankit',’M’, 21,'HISTORY','1998-03-24', 200);
INSERT INTO STU VALUES (3, Anu’,'F', 20,'HINDI','1996-12-12', 300);
INSERT INTO STU VALUES (4,'Bala’,’M’, 19, NULL,'1999-07-01', 400);
INSERT INTO STU VALUES (5,'Charan','M’, 18,'HINDI','1997-06-27', 250);
INSERT INTO STU VALUES (6,'Deepa’,
, 19, HISTORY’,'1997-06-27', 300);
INSERT INTO STU VALUES (7,'Dinesh’
22,'COMPUTER','1997-02-25', 210);
INSERT INTO STU VALUES (8,'Usha’,'F’, 23, NULL,'1997-07-31', 200);
(b) Write a Query to display all the details of the Employees from the above table ‘STU’.
SELECT * FROM STU;
Output:(e) Write a query to Rollno, Name and Department of the students from STU table.
SELECT ROLLNO,NAME,DEPT FROM STU;
(d) Write a Query to select distinct Department from STU table.
SELECT DISTICT(DEPT) FROM STU;
(€) To show all information about students of History department.
SELECT * FROM STU WHERE DEPT='HISTORY';
eryEx.No: 22 SQL COMMANDS EXERCISE - 3
DATE:
AIM:
‘To write Queries for the following Questions based on the given table:
Rollno | Name | Gender | Age Dept DOA Fees
1 Arun M 24 [COMPUTER| 1997-01-10 |" 120
2 ‘Ankit M 21 [nistory | 1998-03-24 | 200
3 ‘Anu F 20 [HINDI 1996-12-12 | 300
4 Bala M 19 | NULL 1999-07-01 | 400
5 Charan | _M 18___| HINDI 1997-09-05 | 250
6 Deepa F 19 | HisToRY [1997-06-27 |" 300
7 Dinesh | __M 22 [COMPUTER | 1997-02-25 [210
8 Usha F 23 [NULL 1997-07-31 | 200
(a) Write a Query to list name of female students in Hindi Department.
SELECT NAME FROM STU WHERE DEPT='HIND!' AND GENDER:
Output:
(b) Write a Query to list name of the students whose ages are between 18 to 20.
SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;
Output:(c) Write a Query to display the name of the students whose name is starting with ‘A’
SELECT NAME FROM STU WHERE NAME LIKE 'A%';
Output:
(@) Write a query to list the names of those students whose name have second alphabet ‘n' in their|
names.
SELECT NAME FROM STU WHERE NAME LIKE ' N%';
Output:Ex.No: 23 ‘SQL COMMANDS EXERCISE - 4
DATE:
AIM:
‘To write Queries for the following Questions based on the given table:
Rolino | Name | Gender | Age Dept DOA Fees
1 ‘Arun M 24 | COMPUTER | 1997-01-10 |~_120
2 Ankit M 21 [HISTORY | 1998-03-24 | 200
3 Anu F 20 [HINDI 1996-12-12 | 300
4 Bala M 19 | NULL 1999-07-01 | 400
5 Charan |~_M 18 | HINDI 1997-09-05 | 250
6 Deepa F 19 | mistory | 1997-06-27 |" 300
7 Dinesh |__M 22 | COMPUTER | 1997-02-25 [210
8 Usha F 23 [NULL 1997-07-31 |__200
(a) Write a Query to delete the details of Roll number is 8.
DELETE FROM STU WHERE ROLLNO=8;
Output (After Deletion)
(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess
is less than 130.
UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;
Output(After Update}(c) Write a Query to add a new column Area of type varchar in table STU.
ALTER TABLE STU ADD AREA VARCHAR(20);
(d) Write a Query to Display Name of all students whose Area Contains NULL.
SELECT NAME FROM STU WHERE AREA IS NULL;
Qutput:
(e) Write a Query to delete Area Column from the table STU,
ALTER TABLE STU DROP AREA;
(f) Write a Query to delete table from Database.
DROP TABLE STU;
Output:
SSSQL COMMANDS EXERCISE - 5
To write Queries for the following Questions based on the given table:
TABLE: UNIFORM
Ucode | Uname |Ucolor| StockDate
1 Shirt | White [2021-03-31
2 Pant__| Black | 2020-01-01
3 Skirt_| Grey [2021-02-18
4 Tie | Bhie_| 2019-01-01
5 Socks | Blue | 2019-03-19
6 Belt | Black [2017-12-09
TABLE: COST
Ucode | Size [Price | Company
1 M_| 500 [Raymond
a L__|-580 |" Mattex
2 | xi | 620 | Mattex
2 M_|810 [Yasin
2 L__| 940 | Raymond,
3 M_| 770 [Yasin
3 L_ | 830 | Galin
4 S__|150_|~ Mattex
{a) To Display the average price of all the Uniform of Raymond Company from table COST.
SELECT AVG(PRICE) FROM COST WHERE COMPANY="RAYMOND';
= |
(b) To display details of all the Uniform in the Uniform table in descending order of Stock date.
SELECT * FROM UNIFORM ORDER BY STOCKDATE DESC;(c) To Display max price and min price of each company.
SELECT COMPANY,MAX(PRICE),MIN(PRICE) FROM COST GROUP BY COMPANY;
Output
(d) To display the company where the number of uniforms size is more than 2
SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING COUNT(*}>2;
Output:
{e) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.
SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM UNIFORM U,COST C WHERE
U.UCODE=C.UCODE;
Outpr
SS