Velammal Vidyalaya Practical Programs-Term2 Class XII-Computer Science 2022-2023
Velammal Vidyalaya Practical Programs-Term2 Class XII-Computer Science 2022-2023
Velammal Vidyalaya Practical Programs-Term2 Class XII-Computer Science 2022-2023
Practical Programs-Term2
Class XII-Computer Science
2022-2023
Program 4-MYSQL 1
Aim: To create a table student and insert values into the table using mysql.
Roll_no integer,
Stuname char(20),
Parent_name char(30),
Class integer,
Address varchar(40));
TABLE : Student
Aim: To create a table stud_data and insert values into the table using MYSQL.
Roll_no integer,
Name char(20),
Marks float(6,2),
Grade char(1),
Section char(2));
TABLE : stud_data
Aim: To execute the MYSQL commands for the following questions using the table student.
Query
Output
5. Output
83.6 A A
106 Sam
76.8 A A
101 Ram
71.2 B A
102 Priya
81.2 A B
103 Rajesh
61.2 B C
104 Riya
51.6 C C
105 Bala
Program 4-MYSQL 4
Aim: To execute the MYSQL commands for the following questions using the table
stud_data.
Query:
Output:
section count(*)
A 3
B 1
C 2
Output:
Output:
Stuname
Rajesh
Riya
Output:
Aim: To create table for teacher and execute the given commands using MYSQL.
Query:
No integer(2),
Name varchar(15),
Age int(3) ,
Department varchar(15),
Dateofjoin varchar(15) ,
Salary int(7) ,
Sex char(1));
Aim: To execute the MYSQL commands for the following questions using the table
Teacher.
order.
Query:
Output:
Output:
Name
Shriya
Output:
Name Dateofjoin
Santhosh 12/12/96
Jishnu 10/01/97
Shakthi 25/02/97
Shiva 27/02/97
Shriya 31/07/97
Ragu 05/09/97
Sharmila 24/03/98
Shanmathi 01/07/99
Output:
count(*)
Output:
Department count(*)
Computer 2
History 3
Maths 3
Program 6
Aim: To integrate SQL with Python by importing the MySQL module to search an
employee using empno and delete the record.
Program Code:
import mysql.connector as mc
mycon=mc.connect(host='localhost',user='root',password='root',database='test')
if mycon.is_connected()==False:
print("Error in connection")
else:
print("Connected")
eno=int(input("Enter number:"))
cursor=mycon.cursor()
cursor.execute("select distinct(empno) from emp")
allrow=cursor.fetchall()
for row in allrow:
if row[0]==eno:
cursor.execute("delete from emp where empno={}".format(eno))
cursor.execute("select * from emp")
data=cursor.fetchall()
mycon.commit()
for row in data:
print(row)
mycon.close()
Output
Connected
Enter num:103
Aim: To integrate SQL with Python by importing the MySQL module to display name started with n.
Program Code:
mycon=sqltor.connect(host="localhost",user="root",password="root",database="test”)
if mycon.is_connected()==False:
print("Error in connection")
else:
print("Connected")
cursor=mycon.cursor()
cursor.execute(st)
data=cursor.fetchall()
for i in data:
print(i)
mycon.close()
Output:
Connected
Aim: To integrate SQL with Python by importing the MySQL module and extracting
if mycon.is_connected( ) == False:
print("Error in connection")
else:
print("Connected")
cursor=mycon.cursor( )
data=cursor.fetchall()
count=cursor.rowcount
print(row)
mycon.close( )
Output:
Connected
Aim: To integrate SQL with Python by importing the MySQL module to display the number
if mycon.is_connected( ) == False:
print("Error in connection")
else:
print("Connected")
cursor=mycon.cursor( )
cursor.execute(st)
str=cursor.fetchone()
print(str)
str=cursor.fetchone()
print()
mycon.close()
Output
Connected
('Delhi', 3)
('Mumbai', 1)
('Bangalore', 1)
Program 10
Aim: To integrate SQL with Python by importing the MySQL module to to search a student
Program Code:
if mycon.is_connected( ) == False:
print("Error in connection")
else:
print("Connected")
cursor=mycon.cursor( )
rollno=int(input("Enter rollno:"))
perc=int(input("Enter percentage:"))
cursor.execute(st)
data=cursor.fetchone()
print(data)
cursor.execute(st)
mycon.commit()
data=cursor.fetchone()
data=cursor.fetchone()
print(data)
mycon.close()
Output
Connected
Enter rollno:106
Enter percentage:76