Prog Codeproj CS
Prog Codeproj CS
GAYATRI KEHRI
KENDRIYA VIDYALAYA VFE
1
2
3
ACKNOWLEDGEMENT
4
5
CREATING A DATABASE AND TABLE IN MYSQL
Make sure that no database with similar name exists. After the
database is successfully created, make a table in database. Using
the code: -
CREATE TABLE class_record ( name varchar (10) , electrostatics
varchar (10) , capacitor int (10) , magnetism int (10) , emi int
(10) , alternating_current int (10) , ray_optics int (10) ,
em_waves int (10) , wave_optics int (10) , modern_physics int
(10) ) ;
After the table is created, we’ll insert name is students and their
marks in monthly / weekly tests.
Fig.1.0
6
fig 1.2 – table class_record
7
8
9
INTERCONNECTING MYSQL AND PYTHON IDLE TO
PERFORM VARIOUS FUNCTIONS.
import mysql.connector
mydb =
mysql.connector.connect(host='localhost',user='root',passwd='
MYSQL')
mycursor = mydb.cursor()
mycursor.execute('use class_project')
mycursor.execute('show tables')
for x in mycursor:
print(x)
10
mycursor.execute('desc class_record')
for i in mycursor:
print(i)
11
12
mycursor.execute ( 'select*from class_record')
for i in mycursor:
print(i)
13
14
mycursor.execute('select name from class_record where
electrostatics <30')
for i in mycursor:
print(i)
15
mycursor.execute("SELECT*from CLASS_RECORD WHERE
ELECTROSTATICS <= (SELECT AVG(ELECTROSTATICS) FROM
CLASS_RECORD)")
for i in mycursor:
print(i)
16
THANK YOU
By: GAYATRI KEHRI
XII B
Roll no. 17
17