Professional Documents
Culture Documents
Certificate
Certificate
IDLE PYTHON
MYSQL
INTRODUCTION
This is a project based on School Management System.
The program helps us to enter, display or alter the
details of the students of the school.
Moreover & most importantly the program helps us to
know the present details of the students.
It includes various function programs to do the above
mentioned tasks.
OBJECTIVE
The main object of the SCHOOL MANAGEMENT
SYSTEM is to reduce time, to provide the details of
students like roll number, admission number etc.
It manages all the information about students.
PROGRAM
DESCRIPTION
A school management system to record the system of
students admission,student record entry and fee deposit
that involves several entities relating to new admission
of students of school and enter students records and
display, manipulate and also can record students fee
details.Thus recording of entries becomes easy and the
expenditure incurred in the working of the organisation
can be easily derived
MySQL
MyQL is an open-source relational database
management system. It allows users to interact a
MySQL database directly using SQL, but more often,
MySQL is used with other programs to implement
applications that need relational database management,
MySQL also enables Python programs to access MySQL
databases.
INDEX
● Certificate
● Acknowledgement
● Hardware and software requirements
● Front and back end
● Introduction
● Objective
● Program description
● MySQL description
● MySQL introduction
● MySQL table structure with records
● Coding
● Output
● Bibliography
Teacher's signature:
HARDWARE AND
SOFTWARE
REQUIREMENTS:
● Software specifications :-
● Operating system: window 10 pro
● Platform : python idle 3.10.2
● Databse :MySQL
● Language :python
● Hardware specifications:-
● Processor :Intel core i 5
● Hard disk 550 gb SSD
● Ram : 16 gb ddr4
CODING
import mysql
import mysql.connector as oxo
from tabulate import tabulate
con = oxo.connect(host="localhost",
user="root",
password"ss",
charset="utf8")
cur = con.cursor()
def show():
print(
"\t------------------------------------\n\
tWELCOME TO SCHOOL MANAGEMENT
SYSTEM\t\n\t----------"
"--------------------------")
print("1.STUDENT MANAGEMENT")
print("2.TEACHER MANAGEMENT")
print("3.FEES MANAGEMENT")
print("4.LIBRARY MANAGEMENT")
print("5:DROP DATABASE")
print("6.Exit")
def create_database():
cur.execute("CREATE DATABASE IF NOT
EXISTS School_2")
cur.execute("USE SCHOOL_2")
cur.execute("""
create table if not exists STUDENT(
ROLLNO INT primary key,
NAME VARCHAR(50),
CLASS VARCHAR(10),
Physics INT not null,
Chemistry INT not null,
Math INT not null,
English INT not null,
Computer INT not null,
tot_percentage decimal(8,3),
tot_marks int not null,
grade varchar(2)
cur.execute("""
create table if not exists TEACHER(
SNO int NOT NULL auto_increment primary
key,
NAME VARCHAR(100),
SUB VARCHAR(50),
SALARY INT)
""")
cur.execute("""
create table if not exists student_teacher (
SNO int NOT NULL auto_increment primary
key,
student_id int not null,
teacher_id int not null,
foreign key (student_id) references
Student(rollno),
foreign key (teacher_id) references
Teacher(SNO)
)
""")
cur.execute("""
create table if not exists
FEES(
SNO int NOT NULL auto_increment primary
key,
SCHOOLFEE INT,
BUSFEE INT,
STUDENT_ID INT,
FEES_PAID bool,
created_at TIMESTAMP DEFAULT
CURRENT_TIMESTAMP ,
updated_at DATETIME DEFAULT
CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
foreign key (STUDENT_ID) references
STUDENT(ROLLNO) )
""")
cur.execute("""
create table if not exists LIBRARY(
SNO int NOT NULL auto_increment primary
key,
BName varchar(50) not null,
AUTHOR VARCHAR(12),
PRICE INT,
student_id int,
submitted_by_student bool,
created_at TIMESTAMP DEFAULT
CURRENT_TIMESTAMP ,
updated_at DATETIME DEFAULT
CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
foreign key (student_id) references
student(rollno)
)
""")
# print(f" {'-' * 10 } All related databases and
tables are created successfully {'-' * 10 } ")
create_database()
show()
# drop database
def drop_database():
cur.execute("DROP DATABASE IF EXISTS
School_2")
con.commit()
print(" Database school_2 is cleaned
successfully ")
# Student Database
def adddata_S():
while True:
rollno = int(input("Enter roll no of student:"))
name = input("Enter name of student:")
Class = input("Enter class of student:")
physics = int(input("Enter physics marks of
student:"))
chemistry = int(input("Enter chemistry marks
of student:"))
maths = int(input("Enter maths marks of
student:"))
english = int(input("Enter english marks of
student:"))
computer = int(input("Enter computer marks
of student:"))
tot_marks = physics + chemistry + english +
computer + maths
tot_percentage = (tot_marks/500) * 100
grade = "E"
if 91 <= tot_percentage <= 100:
grade = "A1"
if 81 <= tot_percentage < 91:
grade = "A2"
if 71 <= tot_percentage < 81:
grade = "B1"
if 61 <= tot_percentage < 71:
grade = "B2"
if 51 <= tot_percentage < 61:
grade = "C1
def fetchdata_S():
try:
def updatedata_S():
roll_number = int(input("Enter the roll
number :"))
update = True
field_update = int(input("\n Which field you
want to update : \n 1: Name \n 2: Class \n 3:
Marks \n "))
if field_update == 1:
field = "name"
value = input("Enter the new name : ")
elif field_update == 2:
field = "class"
value = input("Enter the new class : ")
elif field_update == 3:
field_update = int(input("\n Which subject
marks you want to update :"
" \n 1: Physics \n 2: Maths \n
3: Chemistry \n "
" 4: English \n 5: Computer \
n"))
if field_update == 1:
field = "physics"
value = int(input("Enter the new physics
marks : "))
elif field_update == 2:
field = "math"
value = int(input("Enter the new maths
marks : "))
elif field_update == 3:
field = "chemistry"
value = int(input("Enter the new chemistry
marks : "))
elif field_update == 4:
field = "english"
value = int(input("Enter the new english
marks : "))
elif field_update == 5:
field = "computer"
value = int(input("Enter the new computer
marks : "))
else:
print("bad choice \n exiting to main
menu")
update = False
if update:
cur.execute(
"SELECT {},tot_percentage, tot_marks,
grade FROM STUDENT where
rollno={}".format(field, roll_number)
)
recs = cur.fetchone()
print("current marks: \n")
print(tabulate([recs], headers=[i[0] for i in
cur.description], tablefmt='psql'))
tot_marks = recs[2]
tot_marks -= recs[0]
tot_marks += value
tot_percentage = (tot_marks / 500) * 100
grade = "E"
if 91 <= tot_percentage <= 100:
grade = "A1"
if 81 <= tot_percentage < 91:
grade = "A2"
if 71 <= tot_percentage < 81:
grade = "B1"
if 61 <= tot_percentage < 71:
grade = "B2"
if 51 <= tot_percentage < 61:
grade = "C1"
if 41 <= tot_percentage < 51:
grade = "C2"
if 31 <= tot_percentage < 41:
grade = "D"
try:
sql = "update student set {}={}, {}={}, {}={},
{}='{}' where rollno = {}".format(
field, value, 'tot_percentage',
tot_percentage, 'tot_marks', tot_marks,
'grade', grade, roll_number)
cur.execute(sql)
print("Marks updated")
con.commit()
except Exception as e:
print(e)
update = False
else:
print("bad choice \n exiting to main menu")
update = False
if update:
try:
if field == "tot_marks":
sql = "update student set {} = {} where
rollno = {} ".format(field, value, roll_number)
else:
sql = "update student set {} = '{}' where
rollno = {} ".format(field, value, roll_number)
cur.execute(sql)
print("Records updated")
con.commit()
except Exception as e:
print(e)
def deldata_S():
cursor = con.cursor()
roll_no = int(input("Enter the rollno to be
deleted : "))
try:
query = " delete from student where rollno =
{} ".format(roll_no)
cursor.execute(query)
con.commit()
print(" Deletion Successfull .. ")
except Exception as e:
print(e)
def fetchdata_S_specific():
try:
roll_num = int(input("Enter the student roll
number : "))
cur.execute("SELECT * FROM STUDENT
where rollno={}".format(roll_num))
results = cur.fetchall()
print("Student info : \n")
print(tabulate(results, headers=[i[0] for i in
cur.description], tablefmt='psql'))
def update_S_teacher_info():
try:
teacher_id,
student_id,
teacher_id))
print(f"rows update/created :
{cur.rowcount}")
con.commit()
except mysql.connector.Error as err:
print(f"ERROR:Please check if student id and
teacher id both exist in their respective table :
{err}")
def menu_S():
while True:
print("1 ADD RECORD")
print("2 UPDATE RECORD")
print("3 DELETE RECORD")
print("4 DISPLAY RECORD")
print("5 DISPLAY SPECIFIC STUDENT
DETAILS")
print("6 UPDATE STUDENT 'S TEACHER ")
print("7 EXIT")
choice_S = int(input("ENTER YOUR
CHOICE:"))
if choice_S == 1:
adddata_S()
elif choice_S == 2:
updatedata_S()
elif choice_S == 3:
deldata_S()
elif choice_S == 4:
fetchdata_S()
elif choice_S == 5:
fetchdata_S_specific()
elif choice_S == 6:
update_S_teacher_info()
elif choice_S == 7:
print("EXIT")
break
else:
print("WRONG INPUT")
# For Teacher
def adddata_T():
while True:
try:
name = input("Enter name of Teacher:")
sub = input("Enter Subject of Teacher:")
salary = float(input("Enter Salary of
Teacher:"))
query = "Insert into
teacher(name,sub,salary) values('{}','{}',
{})".format(name, sub, salary)
cur.execute(query)
con.commit()
print("Values Added..")
ch = input("You want to enter more:")
if ch == 'n' or ch == 'N':
break
except Exception as e:
print(e)
def fetchdata_T():
try:
cur.execute("SELECT*FROM TEACHER")
results = cur.fetchall()
print(tabulate(results, headers=[i[0] for i in
cur.description], tablefmt='psql'))
print("Total no. of records:", cur.rowcount)
except:
print("ERROR:UNABLE TO FETCH DATA")
def updatedata_T():
s_no = int(input("Enter the sno for teacher : "))
update = True
field_update = int(input("\n Which field you
want to update : \n 1: Name \n 2: subject \n 3:
Salary \n "))
if field_update == 1:
field = "name"
value = input("Enter the new name : ")
elif field_update == 2:
field = "sub"
value = input("Enter the new Subject : ")
elif field_update == 3:
field = "salary"
value = int(input("Enter the new salary : "))
else:
print("bad choice \n exiting to main menu")
update = False
if update:
try:
if field == "salary":
sql = "update teacher set {} = {} where sno
= {} ".format(field, value, s_no)
else:
sql = "update teacher set {} = '{}' where
sno = {} ".format(field, value, s_no)
cur.execute(sql)
print("Records updated: ", cur.rowcount)
con.commit()
except Exception as e:
print(e)
def deldata_T():
sno = int(input("Enter the sno to be deleted :"))
cursor = con.cursor()
try:
query = " delete from teacher where sno = {}
".format(sno)
cursor.execute(query)
con.commit()
print(" Deletion Successfull .. ")
except Exception as e:
print(e)
def menu_T():
while True:
print("1 ADD RECORD")
print("2 UPDATE RECORD")
print("3 DELETE RECORD")
print("4 DISPLAY RECORD")
print("5 EXIT")
choice_T = int(input("ENTER YOUR
CHOICE:"))
if choice_T == 1:
adddata_T()
elif choice_T == 2:
updatedata_T()
elif choice_T == 3:
deldata_T()
elif choice_T == 4:
fetchdata_T()
elif choice_T == 5:
print("EXIT")
break
else:
print("WRONG INPUT")
# Library
def adddata_L():
while True:
try:
bid = input("Enter BName of Book:")
author = input("Enter Author of Book:")
price = float(input("Enter the Price of
Book:"))
student_id = int(input("enter the roll num
of student to whom you want to issue this book :
"))
submitted_by_student = bool(int(input("0
if book not submitted else 1 ")))
query = "Insert into
library(bname,author,price, student_id,
submitted_by_student) values('{}','{}',{}, {},
{} )".format(
bid,
author,
price,
student_id,
submitted_by_student)
cur.execute(query)
con.commit()
print("Values Added..")
ch = input("You want to enter more:")
if ch == 'n' or ch == 'N':
break
except Exception as e:
print(e)
def fetchdata_L():
try:
def updatedata_L():
try:
cursor = con.cursor()
try:
query = " delete from library where sno = {}
".format(name)
cursor.execute(query)
con.commit()
print(" Deletion Successfull .. ")
except Exception as e:
print(e)
def menu_L():
while True:
print("1 ADD RECORD")
print("2 UPDATE RECORD")
print("3 DELETE RECORD")
print("4 DISPLAY RECORD")
print("5 EXIT")
choice_L = int(input("ENTER YOUR
CHOICE:"))
if choice_L == 1:
adddata_L()
elif choice_L == 2:
updatedata_L()
elif choice_L == 3:
deldata_L()
elif choice_L == 4:
fetchdata_L()
elif choice_L == 5:
print("EXIT")
break
else:
print("WRONG INPUT")
# For Fees
def adddata_F():
while True:
try:
sno = int(input("Enter Roll No of
Student:"))
schoolfee = float(input("Enter School Fees
of Student:"))
busfee = float(input("Enter Bus Fees of
Student:"))
fees_paid = bool(int(input("Enter 0 if fees
not paid else 1 ")))
query = "Insert into
fees(schoolfee,busfee,student_id, fees_paid)
values({},{},{},{})".format(schoolfee,
busfee,
sno,
fees_paid)
cur.execute(query)
con.commit()
print("Values Added..")
ch = input("You want to enter more:")
if ch == 'n' or ch == 'N':
break
except Exception as e:
print(e)
def fetchdata_F():
try:
def updatedata_F():
roll_no = int(input("Enter the roll number :"))
try:
def deldata_F():
name = int(input("Enter the serial num :"))
cursor = con.cursor()
try:
query = " delete from fees where sno ={}
".format(name)
cursor.execute(query)
con.commit()
print(" Deletion Successfull .. ")
except Exception as e:
print(e)
def menu_F():
while True:
print("1 ADD RECORD")
print("2 UPDATE RECORD")
print("3 DELETE RECORD")
print("4 DISPLAY RECORD")
print("5 EXIT")
choice_F = int(input("ENTER YOUR
CHOICE:"))
if choice_F == 1:
adddata_F()
elif choice_F == 2:
updatedata_F()
elif choice_F == 3:
deldata_F()
elif choice_F == 4:
fetchdata_F()
elif choice_F == 5:
print("EXIT")
break
else:
print("WRONG INPUT")
c_F = input("DO YOU WANT TO
CONTINUE OR NOT:")
if c_F == 'n' or c_F == 'N':
break
while True:
choice_M = input("Enter your choice here:")
while not choice_M:
print(" bad choice ")
choice_M = input("Enter your choice again :")
choice_M = int(choice_M)
create_database()
if choice_M == 1:
menu_S()
elif choice_M == 2:
menu_T()
elif choice_M == 3:
menu_F()
elif choice_M == 4:
menu_L()
elif choice_M == 5:
drop_database()
elif choice_M == 6:
print("You exited from the main menu")
break
else:
print("Please choose correct choice")
else:
show()
MYSQL QUERIES
CREATE DATABASE IF NOT EXISTS School_2
USE SCHOOL_2
Sites Referred:
● www.tutorialspoint.com
● www.geeksforgeeks.org
● www.wikipedia.com