Team - 8
Team - 8
import mysql.connector
con=mysql.connector.connect(host="localhost",user="root",password="123456")
while True:
print('\t\t\t\t---------------------------------------------')
print('\t\t\t\tSTUDENT MANAGEMENT SYSTEM ')
print('\t\t\t\t---------------------------------------------')
print('1:Create database\t2:Show databases\t3:Create table\t4:Show tables\t5:Describe table\t6:Add record\t7:Show records\t8:Search record\t9:Update
details\t10:Delete detail\t11:Exit')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
ch=int(input('Enter your choice:'))
if ch==1:
try:
mycursor=con.cursor()
mycursor.execute('create database Student_management_system;')
print('***********Database created successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
except:
print('************Database already exist************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==2:
mycursor=con.cursor()
mycursor.execute('Show databases;')
print('***********Available Databases***********')
for i in mycursor:
print(i)
elif ch==3:
try:
mycursor=con.cursor()
mycursor.execute('use Student_management_system;')
mycursor.execute('create table student(ad int,sname varchar(20),fname varchar(20),class tinyint,dob Date,fmob char(10),primary key(ad));')
print('************Table created successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
except:
print('************Table already created************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==4:
mycursor=con.cursor()
mycursor.execute('use Student_management_system;')
mycursor.execute('show tables;')
print('***************Available Tables*************** ')
for i in mycursor:
print(i)
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==5:
mycursor=con.cursor()
mycursor.execute('use Student_management_system;')
print('************Description of student table************')
mycursor.execute('describe student;')
for i in mycursor:
print(i)
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==6:
op='Y'
while op=='y' or op=='Y':
mycursor=con.cursor()
Admn=int(input('Enter admisson no.:'))
Sname=input('Enter student name:')
Sclass=int(input('Enter student class:'))
Fname=input('Enter student father name:')
dob=input('Enter date of birth of student:')
fmob_no=input('Enter student father mobile no.:')
command='insert into student(ad,sname,class,fname,dob,fmob) values(%s,%s,%s,%s,%s,%s);'
data=(Admn,Sname,Sclass,Fname,dob,fmob_no)
mycursor.execute('use Student_management_system;')
mycursor.execute(command,data)
con.commit()
print(mycursor.rowcount,'Record Inserted.')
op=input('Do you want to insert new record(Y/N):')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==7:
mycursor=con.cursor()
mycursor.execute('use Student_management_system;')
mycursor.execute('select * from student;')
print('************Student Details************ ')
fetch=mycursor.fetchall()
print(fetch)
elif ch==8:
mycursor=con.cursor()
mycursor.execute('use Student_management_system;')
data=input('Enter admission number or name of student:')
command='select * from student where ad like %s or sname like %s;'
n=(data,'%' + data + '%')
print('************Student Details************ ')
mycursor.execute(command,n)
fetch=mycursor.fetchall()
for i in fetch:
print(i)
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==9:
mycursor=con.cursor()
mycursor.execute('use Student_management_system;')
mycursor.execute('select * from student;')
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
print('************You are inside updating details************')
print('1:Update Sname\n2:Update Fname\n3:Update Class\n4:Update DOB\n5:Update Fmob')
opt=int(input('Enter your choice:'))
if opt==1:
N=input('Enter student admission no. whose detail you want to update:')
n=(N,)
command='select * from student where ad=%s;'
mycursor.execute(command,n)
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
A=input('Enter your updated name:')
data=(A,N)
command1=('update student set sname=%s where ad=%s;')
mycursor.execute(command1,data)
con.commit()
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
print('************Data updated successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif opt==2:
N=input('Enter student admission no. whose detail you want to update:')
n=(N,)
command='select * from student where ad=%s;'
mycursor.execute(command,n)
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
B=input('Enter your updated Fname:')
data=(B,N)
command2=('update student set fname=%s where ad=%s;')
mycursor.execute(command2,data)
con.commit()
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
print('************Data updated successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif opt==3:
N=input('Enter student admission no. whose detail you want to update:')
n=(N,)
command='select * from student where ad=%s;'
mycursor.execute(command,n)
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
C=input('Enter your updated Class:')
data=(C,N)
command3=('update student set class=%s where ad=%s;')
mycursor.execute(command3,data)
con.commit()
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
print('************Data updated successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif opt==4:
N=input('Enter student admission no. whose detail you want to update:')
n=(N,)
command='select * from student where ad=%s;'
mycursor.execute(command,n)
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
D=input('Enter your updated DOB:')
data=(D,N)
command4=('update student set dob=%s where ad=%s;')
mycursor.execute(command4,data)
con.commit()
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
print('************Data updated successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif opt==5:
N=input('Enter student admission no. whose detail you want to update:')
n=(N,)
command='select * from student where ad=%s;'
mycursor.execute(command,n)
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
E=input('Enter your updated Fmob:')
data=(E,N)
command5=('update student set Fmob=%s where ad=%s;')
mycursor.execute(command5,data)
con.commit()
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
print('************Data updated successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==10:
mycursor=con.cursor()
mycursor.execute('use Student_management_system;')
mycursor.execute('select * from student;')
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
V=input('Enter student admission no. whose data you want to delete:')
v=(V,)
command2=('delete from student where ad=%s;')
mycursor.execute(command2,v)
con.commit()
fetch=mycursor.fetchall()
for detail in fetch:
print(detail)
print('************Data deleted successfully************')
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
elif ch==11:
mycursor=con.cursor()
print("************Thanks you************")
print('-------------------------------------------------------------------------------------------------------------------------------------------------------')
break
Sample Output
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:1
***********Database created successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:2
***********Available Databases***********
('information_schema',)
('irctc',)
('library',)
('mysql',)
('performance_schema',)
('student_management_system',)
('sys',)
('temprarory',)
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:3
************Table created successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:4
***************Available Tables***************
('student',)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:5
************Description of student table************
('ad', b'int(11)', 'NO', 'PRI', None, '')
('sname', b'varchar(20)', 'YES', '', None, '')
('fname', b'varchar(20)', 'YES', '', None, '')
('class', b'tinyint(4)', 'YES', '', None, '')
('dob', b'date', 'YES', '', None, '')
('fmob', b'char(10)', 'YES', '', None, '')
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:6
Enter admisson no.:1
Enter student name:Kamal
Enter student class:12
Enter student father name:Rambhaj
Enter date of birth of student:2007-10-16
Enter student father mobile no.:9671122679
1 Record Inserted.
Do you want to insert new record(Y/N):y
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter admisson no.:2
Enter student name:Aryan
Enter student class:12
Enter student father name:Bijender
Enter date of birth of student:2008-02-24
Enter student father mobile no.:9812428270
1 Record Inserted.
Do you want to insert new record(Y/N):y
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter admisson no.:3
Enter student name:Ajay
Enter student class:12
Enter student father name:Shubash
Enter date of birth of student:2007-10-12
Enter student father mobile no.:9813536581
1 Record Inserted.
Do you want to insert new record(Y/N):n
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:7
************Student Details************
[(1, 'Kamal', 'Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679'), (2, 'Aryan', 'Bijender', 12, datetime.date(2008, 2, 24), '9812428270'), (3, 'Ajay', 'Shubash', 12,
datetime.date(2007, 10, 12), '9813536581')]
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:8
Enter admission number or name of student:1
************Student Details************
(1, 'Kamal', 'Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:9
(1, 'Kamal', 'Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
(2, 'Aryan', 'Bijender', 12, datetime.date(2008, 2, 24), '9812428270')
(3, 'Ajay', 'Shubash', 12, datetime.date(2007, 10, 12), '9813536581')
************You are inside updating details************
1:Update Sname
2:Update Fname
3:Update Class
4:Update DOB
5:Update Fmob
Enter your choice:1
Enter student admission no. whose detail you want to update:1
(1, 'Kamal', 'Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
Enter your updated name:Kamal Narwal
************Data updated successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:9
(1, 'Kamal Narwal', 'Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
(2, 'Aryan', 'Bijender', 12, datetime.date(2008, 2, 24), '9812428270')
(3, 'Ajay', 'Shubash', 12, datetime.date(2007, 10, 12), '9813536581')
************You are inside updating details************
1:Update Sname
2:Update Fname
3:Update Class
4:Update DOB
5:Update Fmob
Enter your choice:2
Enter student admission no. whose detail you want to update:1
(1, 'Kamal Narwal', 'Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
Enter your updated Fname:Mr. Rambhaj
************Data updated successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:9
(1, 'Kamal Narwal', 'Mr. Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
(2, 'Aryan', 'Bijender', 12, datetime.date(2008, 2, 24), '9812428270')
(3, 'Ajay', 'Shubash', 12, datetime.date(2007, 10, 12), '9813536581')
************You are inside updating details************
1:Update Sname
2:Update Fname
3:Update Class
4:Update DOB
5:Update Fmob
Enter your choice:3
Enter student admission no. whose detail you want to update:2
(2, 'Aryan', 'Bijender', 12, datetime.date(2008, 2, 24), '9812428270')
Enter your updated Class:11
************Data updated successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:9
(1, 'Kamal Narwal', 'Mr. Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
(2, 'Aryan', 'Bijender', 11, datetime.date(2008, 2, 24), '9812428270')
(3, 'Ajay', 'Shubash', 12, datetime.date(2007, 10, 12), '9813536581')
************You are inside updating details************
1:Update Sname
2:Update Fname
3:Update Class
4:Update DOB
5:Update Fmob
Enter your choice:4
Enter student admission no. whose detail you want to update:2
(2, 'Aryan', 'Bijender', 11, datetime.date(2008, 2, 24), '9812428270')
Enter your updated DOB:2008-02-26
************Data updated successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:9
(1, 'Kamal Narwal', 'Mr. Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
(2, 'Aryan', 'Bijender', 11, datetime.date(2008, 2, 26), '9812428270')
(3, 'Ajay', 'Shubash', 12, datetime.date(2007, 10, 12), '9813536581')
************You are inside updating details************
1:Update Sname
2:Update Fname
3:Update Class
4:Update DOB
5:Update Fmob
Enter your choice:5
Enter student admission no. whose detail you want to update:1
(1, 'Kamal Narwal', 'Mr. Rambhaj', 12, datetime.date(2007, 10, 16), '9671122679')
Enter your updated Fmob:8814923723
************Data updated successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:10
(1, 'Kamal Narwal', 'Mr. Rambhaj', 12, datetime.date(2007, 10, 16), '8814923723')
(2, 'Aryan', 'Bijender', 11, datetime.date(2008, 2, 26), '9812428270')
(3, 'Ajay', 'Shubash', 12, datetime.date(2007, 10, 12), '9813536581')
Enter student admission no. whose data you want to delete:3
************Data deleted successfully************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------
STUDENT MANAGEMENT SYSTEM
---------------------------------------------
1:Create database 2:Show databases 3:Create table 4:Show tables 5:Describe table 6:Add record 7:Show records 8:Search record
9:Update details 10:Delete detail 11:Exit
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Enter your choice:11
************Thanks you************
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------