0% found this document useful (0 votes)
12 views55 pages

0 - Practical File - 0

python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views55 pages

0 - Practical File - 0

python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

KENDRIYA VIDYALAYA

PUSHP VIHAR

COMPUTER SCIENCE (083)


PRACTICLE FILE (2024-25)

SUBMITTED BY: VIVAAN SINHA


CLASS: XII ‘A’
INDEX
PYTHON PROGRAMMING

S. No. Practical
1 Write a python program to search an element in a list and display the
frequency of elements present in the list and their location using
Linear search by using a user defined function.
2 Write a program to count frequency of words “his” or “her” in a text
file.
3 Write a python program to pass a list to a function and double the
odd values and half even values of a list and display list elements
after changing.
4 Write a Python program input n numbers in tuple and pass it to
function to count how many even and odd numbers are entered.

5 Write a Python program to function with key and value, and update
value at that key in the dictionary entered by the user.

6 Write a Python program to pass a string to a function and count how


many vowels present in the string.
7 Write a Python program to generate (Random Number) that
generates random numbers between 1 and 6 (simulates a dice) using
a user defined function.

8 Write a menu driven python program to implement 10 python


mathematical functions.
9 Write a menu driven program in python to delete the name of a
student from the dictionary and to search phone no of a student by
student name.
10 Write a python program to read and display file content line by line
with each word separated by #.
11 Write a python program Read a text file and display the number of
vowels, consonants, upper case, lower case characters in the file.
12 Write a Menu driven program in python to count spaces, digits,
words and lines from text file TOY.txt
13 Write a python program to remove all the lines that contain the
character “a‟ from file “sample.txt” and write it to another file
“newfile.txt”.
14 Write a python program to create a binary file with name and roll
number. Search for a given roll number and display name, if not
found display appropriate message.
15 Write a python program using list having roll number, name and
marks. Accept 5 records from the user and write them into a binary
file.
16 Write a python program to create a CSV file by entering user-id and
password, read and search the password for given user-id.
17 Write a menu driven python program to create a CSV file by entering
dept-id, name and city. Read and search the record for given dept-id.
18 Write a Python program to implement a stack using list (PUSH & POP
Operations on Stack).
19 Write a python program using the function PUSH(Arr), where Arr is a
list of numbers. From this list push all numbers divisible by 5 into a
stack implemented by using a list. Display the stack if it has at least
one element, otherwise display appropriate error messages.
20 Write a python program using function POP(Arr), where Arr is a stack
implemented by a list of numbers. The function returns the value
deleted from the stack.
SQL QUERIES
S. No. Practical
1 Create a student table with the student id, name, Gender,and marks
as attributes where the student id is the primary key.
2 Insert the details of a 5 new student in the above table.

3 Delete the details of a student in the above table using a condition.


4 Use the select command to get the details of the students with
marks more than 80.
5 Find the min, max, sum, and average marks in a student table.
6 Add a new Column stream in the student table whose datatype is
varchar and size is 30.
7 Modify the size of stream column from 30 to 40.

8 Update the marks of all students by 10


9 Write a SQL query to order the (student ID, marks) table in
descending order of the marks.

10 Find the total number of students of each gender in the using group
by
11 Find the total number of girls who scored more than 75 marks

12 Write command to show all names starting with “r”.


13 Delete the student Table
14 Create a school Database and then create a student table in the
school database and insert data. Implement the following SQL
commands on the student table: ALTER table to add new
attributes, UPDATE table to modify data, ORDER By to display data
in ascending / descending order, DELETE to remove tuple(s),
GROUP BY, Find the min, max, sum, count,count(*) and average
13 Delete the student Table
14 Create a school Database and then create a student table in the
school database and insert data. Implement the following SQL
commands on the student table: ALTER table to add new
attributes, UPDATE table to modify data, ORDER By to display data
in ascending / descending order, DELETE to remove tuple(s),
GROUP BY, Find the min, max, sum, count,count(*) and average
15 Write a program to connect Python with MySQL using database
connectivity and perform the following operations on data in
database: Fetch, Update and delete the data
16 Integrate SQL with Python by importing the MySQL module insert
record of employees and displaying the record
17 Integrate SQL with Python by importing the MySQL module to
search an employee using empno and if present in table display
the record, if not display appropriate method.
18 Integrate SQL with Python by importing the MySQL module to
update a student using rollno and delete a record using rollno.
PYTHON PROGRAMMING
1) Write a python program to search an element in a list and display the
frequency of elements present in the list and their location using Linear
search by using a user defined function. [List and search element should
be entered by user]

n=int(input("Enter no. of elements in list: "))


L=[]
for i in range (n):
a=input("Enter element of list: ")
L.append(a)
print()
print("List: ",L)
print()
s=input("Enter an element to search: ")
def search(s):
c=0
l=[]
for i in range (len(L)):
if L[i]==s:
c+=1
l.append(i+1)
return c,l
x=search(s)
print("Frequency of",s,"in the list : ",x[0])
if x[0]==0:
print(s,"is not present in the list")
else:
print("Positions of",s,"in the list : ",x[1])
OUTPUT 1:

Enter no. of elements in list: 3


Enter element of list: 19
Enter element of list: hi
Enter element of list: 19

List: ['19', 'hi', '19']

Enter an element to search: 19


Frequency of 19 in the list : 2
Positions of 19 in the list : [1, 3]

OUTPUT 2:

Enter no. of elements in list: 3


Enter element of list: 89
Enter element of list: hello
Enter element of list: world

List: ['89', 'hello', 'world']

Enter an element to search: hi


Frequency of hi in the list : 0
hi is not present in the list
2) Write a program to count frequency of words “his” or “her” in a text
file.

with open('file.txt','r') as f:
s=f.read()
l=s.split()
c1=0
c2=0
for i in l:
if i.lower()=='his':
c1+=1
elif i.lower()=='her':
c2+=1
print('Frequency of his in the file:',c1)
print('Frequency of her in the file:',c2)

OUTPUT :

Frequency of his in the file: 3


Frequency of her in the file: 4
3) Write a python program to pass a list to a function and double the
odd values and half even values of a list and display list elements
after changing.

L=[2,11,16,19,8,3]
l=[]
def func(L):
for i in L:
if i%2==0:
i=i/2
l.append(i)
else:
i=i*2
l.append(i)
return l
print("List before changing: ",L)
print("List after changing: ",func(L))

OUTPUT :

List before changing: [2, 11, 16, 19, 8, 3]


List after changing: [1.0, 22, 8.0, 38, 4.0, 6]
4) Write a Python program input n numbers in tuple and pass it to
function to count how many even and odd numbers are
entered.

t=()
n=int(input("Enter no. of elements in tuple: "))
for i in range(n):
a=int(input("Enter number in tuple: "))
t+=(a,)
e=0
o=0
for i in t:
if i%2==0:
e+=1
else:
o+=1
print("Tuple: ",t)
print("No. of odd numbers in tuple: ",o)
print("No. of even numbers in tuple: ",e)

OUTPUT :

Enter no. of elements in tuple: 3


Enter number in tuple: 13
Enter number in tuple: 66
Enter number in tuple: 2
Tuple: (13, 66, 2)
No. of odd numbers in tuple: 1
No. of even numbers in tuple: 2
5) Write a Python program to function with key and value, and update
value at that key in the dictionary entered by the user.

dic={}
while True:
k=input("Enter key: ")
v=input("Enter value: ")
dic[k]=v
u=input("Do you want to add more? (y/n) :")
if u.lower()!='y':
break

print()
print("Your dictionary: ",dic)
print()

def update(K,V):
dic[K]=V
return dic

key=input("Enter key to be updated: ")


if key in dic.keys():
val=input("Enter new value : ")
print()
D=update(key,val)
print("Dictionary after updating: ",D)

else:
print()
print('No key named',key,'is present in dictionary')
OUTPUT 1:
Enter key: apple
Enter value: red
Do you want to add more? (y/n) :y
Enter key: grapes
Enter value: black
Do you want to add more? (y/n) :n

Your dictionary: {'apple': 'red', 'grapes': 'black'}

Enter key to be updated: grapes


Enter new value : green

Dictionary after updating: {'apple': 'red', 'grapes': 'green'}

OUTPUT 2:
Enter key: apple
Enter value: red
Do you want to add more? (y/n) :n

Your dictionary: {'apple': 'red'}

Enter key to be updated: ap

No key named ap is present in dictionary


6) Write a Python program to pass a string to a function and count
how many vowels present in the string.

def countvowel(s):
c=0
for i in s:
if i.lower() in ['a','e','i','o','u']:
c+=1
return c
S=input("Enter a sting: ")
v=countvowel(S)
print('No. of vowels in " ',S,' " : ',v)

OUTPUT :

Enter a sting: Hello World


No. of vowels in " Hello World " : 3
7) Write a Python program to generate (Random Number) that
generates random numbers between 1 and 6 (simulates a dice)
using a user defined function.

def dice():
import random
a=random.randint(1,6)
return a

while True:
print("You rolled: ",dice())
u=input("Do you want to roll again? (y/n) :")
if u.lower()!='y':
break

OUTPUT :

You rolled: 4
Do you want to roll again? (y/n) :y
You rolled: 1
Do you want to roll again? (y/n) :y
You rolled: 3
Do you want to roll again? (y/n) :n
8) Write a menu driven python program to implement 10 python
mathematical functions.

print("----------------MENU----------------")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Square")
print("6. Square root")
print("7. Raising an exponent")
print("8. Log with a custom base")
print("9. Smallest integer")
print("10. Factorial")
print("11. Exit")
print("="*50)
import math
while True:
u=int(input("Enter your choice: "))
if u==1:
a=int(input("Enter a number: "))
b=int(input("Enter a number: "))
print(a+b)
elif u==2:
a=int(input("Enter a number: "))
b=int(input("Enter a number: "))
print(a-b)
elif u==3:
a=int(input("Enter a number: "))
b=int(input("Enter a number: "))
print(a*b)
elif u==4:
a=int(input("Enter a number: "))
b=int(input("Enter a number: "))
print(a/b)
elif u==5:
a=int(input("Enter a number: "))
print(a**2)
elif u==6:
a=int(input("Enter a number: "))
print(math.sqrt(a))
elif u==7:
a=int(input("Enter base: "))
b=int(input("Enter power: "))
print(math.pow(a,b))
elif u==8:
a=int(input("Enter a number: "))
b=int(input("Enter base: "))
print(math.log(a,b))
elif u==9:
a=float(input("Enter a number: "))
print(math.ceil(a))
elif u==10:
a=int(input("Enter a number: "))
print(math.factorial(a))
elif u==11:
print("Exiting program")
print("="*50)
break
else:
print("Oops! Incorrect choice")
print("="*50)
OUTUPUT:
----------------MENU----------------
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Square
6. Square root
7. Raising an exponent
8. Log with a custom base
9. Smallest integer
10. Factorial
11. Exit
==================================================
Enter your choice: 1
Enter a number: 2
Enter a number: 3
5
==================================================
Enter your choice: 8
Enter a number: 64
Enter base: 4
3.0
==================================================
Enter your choice: 9
Enter a number: 3.8
4
==================================================
Enter your choice: 11
Exiting program
==================================================
9) Write a menu driven program in python to delete the name of a
student from the dictionary and to search phone no of a student by
student name. Create menu as below:
MENU
1. Delete from Dictionary
2. Search Phone number using name from Dictionary
3. Exit

numbers = {'Atul':'9967884589', 'Abhinay':'8938572946' ,


'Vinay':'1289452967','Anshi':'1234567890','Preeti':'4589240087'}
print("------------------MENU------------------")
print("1. Show dictionary")
print("2. Delete from Dictionary ")
print("3. Search Phone number using name from Dictionary ")
print("4. Exit")
print('='*100)
while True:
u=int(input("Enter your choice: "))
if u==1:
print(numbers)
elif u==2:
n=input("Enter name: ").title()
b=numbers.pop(n)
elif u==3:
n=input("Enter name: ").title()
print("Phone number of",n,":",numbers[n])
elif u==4:
print("Exiting program")
print('='*100)
break
else:
print("Oops! Incorrect choice")
print('='*100)

OUTPUT :
------------------MENU------------------
1. Show dictionary
2. Delete from Dictionary
3. Search Phone number using name from Dictionary
4. Exit
=========================================================
Enter your choice: 1
{'Atul': '9967884589', 'Abhinay': '8938572946', 'Vinay': '1289452967',
'Anshi': '1234567890', 'Preeti': '4589240087'}
=========================================================
Enter your choice: 2
Enter name: atul
=========================================================
Enter your choice: 3
Enter name: vinay
Phone number of Vinay : 1289452967
=========================================================
Enter your choice: 1
{'Abhinay': '8938572946', 'Vinay': '1289452967', 'Anshi': '1234567890',
'Preeti': '4589240087'}
=========================================================
Enter your choice: 4
Exiting program
=========================================================
10) Write a python program to read and display file content line by
line with each word separated by #.

with open('file.txt', 'r') as f:


L=f.readlines()
for line in L:
l = line.split()
for word in l:
print(word, end='#')
print()

OUTPUT :

Hi#I#am#Vivaan#Sinha#
I#am#17#years#old#
This#is#my#computer#science#practical#
11) Write a python program Read a text file and display the number
of vowels, consonants, upper case, lower case characters in the file.
with open('file.txt','r') as f:
s=f.read()
v,c,u,l=0,0,0,0
for i in s:
if i.isupper():
u+=1
if i.lower() in 'aeiou' :
v+=1
elif i.lower() not in 'aeiou' :
c+=1
elif i.islower():
l+=1
if i.lower() in 'aeiou' :
v+=1
elif i.lower() not in 'aeiou' :
c+=1
print(s)
print("No. of consonants : ",c)
print("No. of vowels : ",v)
print("No. of upper case letters : ",u)
print("No. of lower case letters : ",l)

OUTPUT :
Hi I am Vivaan Sinha
I am 17 years old
This is my computer science practical
No. of consonants : 35
No. of vowels : 24
No. of upper case letters : 6
No. of lower case letters : 53
12) Write a Menu driven program in python to count spaces,
digits, words and lines from text file TOY.txt

f=open('Toy.txt')
S=f.read()
print("-----------------------MENU-----------------------")
print("1. Show File")
print("2. Count Spaces")
print("3. Count Digits")
print("4. Count words")
print("5. Count Lines")
print("6. Exit")
print('='*50)
s=d=w=l=0
for i in S:
if i.isspace():
s+=1
elif i.isdigit():
d+=1
elif i.isalpha():
w+=1
while True:
u=int(input("Enter your choice: "))
if u==1:
print(S)
elif u==2:
print("No. of spaces:",s)
elif u==3:
print("No. of digits:",d)
elif u==4:
print("No. of words:",w)
elif u==5:
f.close()
f=open('Toy.txt','r')
L=f.readlines()
print("No. of lines:",len(L))
elif u==6:
print("Exiting program")
print('='*50)
break
else:
print("Oops! Incorrect Choice")
print('='*50)
OUTPUT :
-----------------------MENU-----------------------
1. Show File
2. Count Spaces
3. Count Digits
4. Count words
5. Count Lines
6. Exit
==================================================
Enter your choice: 1
Hi I am Vivaan Sinha
I am 17 years old
This is my computer science practical
==================================================
Enter your choice: 2
No. of spaces: 15
==================================================
Enter your choice: 3
No. of digits: 2
==================================================
Enter your choice: 4
No. of words: 59
==================================================
Enter your choice: 5
No. of lines: 3
==================================================
Enter your choice: 6
Exiting program
==================================================
13) Write a python program to remove all the lines that contain
the character “a‟ from file “sample.txt” and write it to another
file “newfile.txt”.

f=open('sample.txt','r')
l=f.readlines()
print(l)
L=[]
for i in l:
if 'a' in i :
L.append(i)
l.remove(i)
f.close()

f=open('sample.txt','w')
f.writelines(l)
f.close()

f=open('newfile.txt','w')
f.writelines(L)
f.close()
print('='*50)

f=open('sample.txt','r')
print(f.readlines())
f.close()
print('='*50)
f=open('newfile.txt','r')
print(f.readlines())
f.close()
print('='*50)

OUTPUT :

['Hi, My name is Vivaan\n', 'I study in 12th\n', 'My school is KV Pushp


Vihar\n', 'This is my file']
==================================================
['I study in 12th\n', 'This is my file']
==================================================
['Hi, My name is Vivaan\n', 'My school is KV Pushp Vihar\n']
==================================================
14) Write a python program to create a binary file with name
and roll number. Search for a given roll number and display
name, if not found display appropriate message.

import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number : "))
name= input("Enter Name : ")
student.append([roll,name])
ans=input("Add More ? (y/n): ")
print('='*50)
pickle.dump(student,f)
f.close()
l=[]
f=open('student.dat','rb')
try:
while True:
l=pickle.load(f)
except EOFError:
pass
while True:
found=False
r=int(input("Enter roll no. to search: "))
for s in l:
if s[0]==r:
print("Name of student is: ",s[1])
found=True
if found==False:
print("Roll no. not found")
ans=input("Want to search more? (y/n): ")
print('='*50)
if ans.lower()!='y':
print("Exiting program")
print('='*50)
break
f.close()
OUTPUT :
Enter Roll Number : 1
Enter Name : abhi
Add More ? (y/n): y
==================================================
Enter Roll Number : 2
Enter Name : preeti
Add More ? (y/n): y
==================================================
Enter Roll Number : 18
Enter Name : vinay
Add More ? (y/n): n
==================================================
Enter roll no. to search: 1
Name of student is: abhi
Want to search more? (y/n): y
==================================================
Enter roll no. to search: 15
Roll no. not found
Want to search more? (y/n): n
==================================================
Exiting program
==================================================
15) Write a python program using list having roll number, name
and marks. Accept 5 records from the user and write them into a
binary file.

import pickle
f=open('students.dat','wb')
l=[]
for i in range (5):
r=int(input("Enter roll no.: "))
n=input("Enter name: ")
m=int(input("Enter marks: "))
print('='*50)
l.append([r,n,m])
pickle.dump(l,f)
f.close()
f=open('students.dat','rb')
try:
while True:
s=pickle.load(f)
except EOFError:
pass
print("%10s"%'Roll no.','%20s'%'Name','%30s'%'Marks')
print('='*50)
for i in s:
print("%10s"%i[0],'%20s'%i[1],'%30s'%i[2])
print('='*50)
OUTPUT :
Enter roll no.: 1
Enter name: abhi
Enter marks: 95
==================================================
Enter roll no.: 2
Enter name: preeti
Enter marks: 99
==================================================
Enter roll no.: 3
Enter name: vinay
Enter marks: 92
==================================================
Enter roll no.: 4
Enter name: riya
Enter marks: 65
==================================================
Enter roll no.: 5
Enter name: ajay
Enter marks: 57
==================================================
Roll no. Name Marks
==================================================
1 abhi 95
2 preeti 99
3 vinay 92
4 riya 65
5 ajay 57
==================================================
16) Write a python program to create a CSV file by entering user-id
and password, read and search the password for given user-id.

import csv
with open("record.csv","a") as f:
fw=csv.writer(f)
while True:
uid = input("Enter id: ")
password = input("Enter password: ")
fw.writerow([uid,password])
ans=input("Want to continue? (y/n) :")
print('='*50)
if ans.lower()!='y':
break

with open("record.csv","r") as f:
fr=csv.reader(f)
u=input("Enter use it to search: ")
for i in fr:
if i!=[]:
if i[0] == u:
print("Password: ",i[1])
break
OUTPUT :

Enter id: abhi


Enter password: abhi@1234
Want to continue? (y/n) :y
==================================================
Enter id: riya
Enter password: AlPha@riya
Want to continue? (y/n) :y
==================================================
Enter id: vinay
Enter password: vinay.1234
Want to continue? (y/n) :n
==================================================
Enter use it to search: vinay
Password: vinay.1234
17) Write a menu driven python program to create a CSV file by
entering dept-id, name and city. Read and search the record for
given dept-id.
MENU
1. Create csv file
2. Search record as per dept no
3.Exit

import csv
print('-----------------------MENU-----------------------')
print('1: create csv file')
print('2: Search as per dept no.')
print('3: Exit')
print('='*50)
while True:
ch=int(input('Enter choice: '))
if ch==1:
f=open('dept.csv','a')
fw=csv.writer(f)
ans='y'
print('-'*50)
while ans.lower()=='y':
dno=int(input('Enter dept no:'))
name=input('Enter dept name:')
city=input('Enter city:')
fw.writerow([dno,name,city])
ans=input('Add More? (y/n): ')
print('-'*50)
print('='*50)
f.close()
elif ch==2:
f=open('dept.csv','r')
r=input('Enter DEPT no you want to search :')
fr=csv.reader(f)
for rec in fr:
if rec!=[]:
if rec[0]==r:
print("Dept no =",rec[0])
print("Dept Name =",rec[1])
print("City =",rec[2])
print('='*50)
f.close()
elif ch==3:
print("Exiting program")
print("="*50)
break
else:
print("Oops! Incorrect option")
OUTPUT :
-----------------------MENU-----------------------
1: create csv file
2: Search as per dept no.
3: Exit
==================================================
Enter choice: 1
--------------------------------------------------
Enter dept no:12
Enter dept name:Maths
Enter city:Indore
Add More? (y/n): y
--------------------------------------------------
Enter dept no:23
Enter dept name:Hindi
Enter city:Pune
Add More? (y/n): n
--------------------------------------------------
==================================================
Enter choice: 2
Enter DEPT no you want to search :23
Dept no = 23
Dept Name = Hindi
City = Pune
==================================================
Enter choice: 3
Exiting program
==================================================
18) Write a Python program to implement a stack using list
(PUSH & POP Operations on Stack).

print(“***********STACK DEMONSTRATION************”)
print("1. TRAVERSE ")
print("2. PUSH")
print("3. POP")
print("4. Exit")
print("="*50)
ans='y'
S=[]
while ans.lower()=='y':
ch = int(input("Enter your choice :"))
if ch==1:
if S==[]:
print("Stack is empty")
else:
n=len(S)
for i in range (-1,-n-1,-1):
print(S[i])
print("="*50)
elif ch==2:
a=input("Enter element to push: ")
S.append(a)
print("="*50)
elif ch==3:
if S==[]:
print("Stack is empty")
else:
p=S.pop()
print("Popped",p,"from stack")
print('='*50)
elif ch==4:
print("Exiting program")
print('='*50)
break
else:
print("Oops! Incorrect choice")
*************** STACK DEMONSTRATION***************
1. TRAVERSE
2. PUSH
3. POP
4. Exit
==================================================
Enter your choice :2
Enter element to push: Hello
==================================================
Enter your choice :2
Enter element to push: World
==================================================
Enter your choice :2
Enter element to push: Hi
==================================================
Enter your choice :1
Hi
World
Hello
==================================================
Enter your choice :3
Popped Hi from stack
==================================================
Enter your choice :1
World
Hello
==================================================
Enter your choice :4
Exiting program
==================================================
19) Write a python program using the function PUSH(Arr), where Arr
is a list of numbers. From this list push all numbers divisible by 5
into a stack implemented by using a list. Display the stack if it has at
least one element, otherwise display appropriate error messages.

def PUSH(Arr):
stack=[]
for i in Arr:
if i%5==0:
stack.append(i)
if len(stack)==0:
print("No element is divisible by 0")
else:
print("Stack:",stack)
#Example :-
Arr = [1,3,5,15,34,95]
PUSH(Arr)

OUTPUT :

Stack: [5, 15, 95]


20) Write a python program using function POP(Arr), where Arr
is a stack implemented by a list of numbers. The function
returns the value deleted from the stack.

def POP(Arr):
if len(Arr)==0:
print("Stack is empty")
else:
p=Arr.pop()
print("Popped",p,"from stack")
#Example :-
Arr = [1,3,5,15,34,95]
print("Stack:", Arr)
POP(Arr)

OUTPUT :

Stack: [1, 3, 5, 15, 34, 95]


Popped 95 from stack
SQL QUERIES

1) Create a student table with the student id, name, Gender,and


marks as attributes where the student id is the primary key.

2) Insert the details of 5 new student in the above table.


3) Delete the details of a student in the above table using a condition.
4) Use the select command to get the details of the students with
marks more than 80.

5) Find the min, max, sum, and average marks in a student table.
6) Add a new Column stream in the student table whose datatype is
varchar and size is 30.

7) Modify the size of stream column from 30 to 40.


8) Update the marks of all students by 10

9) Write a SQL query to order the (student ID, marks) table in


descending order of the marks.
10) Find the total number of students of each gender in the using
group by

11) Find the total number of girls who scored more than 75 marks
12) Write command to show all names starting with “r”

13) Delete the student Table

14) Create a school Database and then create a student table in the
school database and insert data. Implement the following SQL
commands on the student table:
ALTER table to add new attributes / modify data type / drop attribute
UPDATE table to modify data
ORDER By to display data in ascending / descending order
DELETE to remove tuple(s)
GROUP BY
Find the min, max, sum, count, count(*) and average
 Creating Database:

 Creating Table:

 Inserting values in Table:


 Adding new attribute:

 Updating data:

 Table after updating:


 U:
 Order by marks (ascending / descending):

 Deleting a tuple:
 Table after deleting a tuple:
 U:

 Grouping the table with aggregate functions:


 U:

You might also like