0% found this document useful (0 votes)
7 views8 pages

MySQL Database Management for Class 12B

The document contains Python code for managing a MySQL database named 'clas12A' with a table 'salary'. It includes functionalities for creating the database, inserting records, updating salary details, and displaying records based on various criteria. The code also provides a menu-driven interface for user interaction to perform different database operations.

Uploaded by

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

MySQL Database Management for Class 12B

The document contains Python code for managing a MySQL database named 'clas12A' with a table 'salary'. It includes functionalities for creating the database, inserting records, updating salary details, and displaying records based on various criteria. The code also provides a menu-driven interface for user interaction to perform different database operations.

Uploaded by

vedkavathiya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#Name:Kunal

#class:12B
#ROLL no: 21
#Q18
import [Link] as ms
mydb=[Link](host='localhost',user='root',password='Dps@123')
cur= [Link]()
[Link]("Create database clas12a")
[Link]("use clas12a")
[Link]("show tables")
[Link]('create table salary (code int,name varchar(40),bsal
float,hra float,mobile int)')
[Link] ('desc salary')
print('table created')
def recordsinsertion():
mydb=
[Link](host='localhost',user='root',password='Dps@123')
cur= [Link]()
[Link]("use clas12A")
[Link]('INSERT INTO SALARY VALUES (202023, "SHWETA
MATHEW", 120000.0, 12000.0, 65932171)')
[Link]("INSERT INTO SALARY VALUES (202014, 'MANISH
PANDEY', 140000.0, 14000.0, 95980168)")
[Link]("INSERT INTO SALARY VALUES (202047, 'GURAV
KUMAR', 170000.0, 17000.0, 55917452)")
[Link] ("INSERT INTO SALARY VALUES (202038, 'ANJU
CHADHA', 180000.0, 18000.0, 55288335)")
[Link] ("INSERT INTO SALARY VALUES (202027, 'ROBERT
GEORGE', 150000.0, 15000.0, 95747618)")
[Link] ("INSERT INTO SALARY VALUES (202018, 'PIYALI
DUTT', 160000.0, 16000.0, 97211059)")
[Link] ("INSERT INTO SALARY VALUES (202045, 'AJAY
CHACKO', 145000.0, 14500.0, 66806709)")
[Link] ("INSERT INTO SALARY VALUES (202013, 'SAMINA
KHATUN', 125000.0, 12500.0, 68965861)")
[Link] ("INSERT INTO SALARY VALUES (202140, 'PRAKASH
GULATI', 135000.0, 13500.0, 55715185)")
[Link] ("INSERT INTO SALARY VALUES (202120, 'SUMAN
KOTHARI', 130000.0, 13000.0, 55437984)")
[Link] ("INSERT INTO SALARY VALUES (202110, 'PETER
WILLIAMS', 175000.0, 17500.0, 98687010)")
[Link] ("INSERT INTO SALARY VALUES (202130, 'SAGARIKA
GHOSH', 155000.0, 15500.0, 96528668)")
[Link] ("INSERT INTO SALARY VALUES (202133, 'VIVEK
JACOB', 140000.0, 14000.0, 67977642)")
[Link] ("INSERT INTO SALARY VALUES (202122, 'RAKESH
SHARMA', 130000.0, 13000.0, 97296186)")
[Link]()
[Link]()
print('values are inputted')
def additionofrecords():
for k in range(2):
code=int(input("enter code"))
name=input("enter name")
mobile=int(input("enter a 8 digit mobile no:"))
bsal=float(input("enter salary"))
hra=float(input("enter hra"))
[Link]("use clas12A")
[Link](f"insert into salary values ({code},'{name}',
{mobile},{bsal},{hra})")
print("ready")
def name():
name1=input("enter a name")
[Link]("select * from salary where
name={}".format(name1))
def display():
[Link]("use clas12A")
[Link]("select * from salary")
def displays():
[Link]("use clas12A")
[Link]("select * from salary order by code")
while True:
print("1. CREATE THE TABLE AND DB")
print("2. COPY THE RECORDS")
print("3. INPUT YOUR OWN VALUES")
print("4. INPUT YOUR NAME AND CHECK IF IT IS THERE IN THE
DB")
print("5. display the table")
print("6. display the table sorted by code")
print("0. exit the menu")
ch=int(input("enter the choice preffered"))
if ch==1:
tablecreation()
elif ch==2:
recordsinsertion()
elif ch==3:
additionofrecords()
elif ch==4:
name()
elif ch==5:
display()
elif ch==6:
displays()
elif ch==0:
print("exiting menu ")
else:
print ("choice invalid")
#Name:Kunal Singh
#class:12B
#ROLL no: 21
#Q19:
import [Link] as ms
mydb= [Link](host='localhost',user='root',password='Dps@123',
Database='clas12A')
cur= [Link]()
[Link]("use clas12a")
[Link]("show tables")
[Link] ('desc salary')
print('table created')
def sortinganddisplaying():
mydb=
[Link](host='localhost',user='root',password='Dps@123')
cur= [Link]()
[Link]("use clas12A")
[Link]('select * from salary order by bsal')
s=[Link]()
for k in s:
print(k[0],k[1],k[2],k[3],k[4])
[Link]()
def DISPLAYBSAL():
mydb=
[Link](host='localhost',user='root',password='Dps@123')
cur= [Link]()
[Link]("use clas12A")
[Link]("select * from salary where bsal>135000 and
bsal<160000")
s=[Link]()
for k in s:
print(k[0],k[1],k[2],k[3],k[4])
[Link]()
def INCREASEHRA():
mydb=
[Link](host='localhost',user='root',password='Dps@123')
cur= [Link]()
[Link]("use clas12A")
[Link]("update salary set Hra= Hra + 0.15*bsal")
[Link]()
[Link]("select * from salary ")
s=[Link]()
for k in s:
print(k[0],k[1],k[2],k[3],k[4])
[Link]()

def newcolumn():
ydb=
[Link](host='localhost',user='root',password='Dps@123')
cur= [Link]()
[Link]("use clas12A")
[Link]("alter table salary add column bonus float")
[Link]()
[Link]("update salary set Bonus= 0.05* Bsal")
[Link]()

def deletcolumn():
mydb=
[Link](host='localhost',user='root',password='Dps@123')
cur= [Link]()
[Link]("use clas12")
CODE1=int(input("enter the code input required to search"))
[Link](f"delete from salary where code={CODE1}")
[Link]()
[Link](f"select * from salary where code={CODE1}")
s=[Link]()
for k in s:
if code1==k[0]:
print("INPUTTED CODE SUCCESSFULLY FOUND!")
else:
print("Not found ")
while True:
print("1. SORTING AND SIAPLY THE RECORDS AND ROWS")
print("2. DISPLAYING THE ROWS AND RECORDS WITH BSAL SORTING")
print("3. INCREASE AND UPDATE THE FUCNTION OF HRA")
print("4. UPDATE AND ALTER AND ADD A NEW COLUMN")
print("5. DELETE THE RECORD OR ROW BASED ON THE INPUTTED CODE
AND CHECK WITH THE FORMAT METHOD")
print("0. EXIT THE MENU")

ch=int(input("enter the choice prefered"))

if ch==1: sortinganddisplaying()
elif ch==2: DISPLAYBSAL()
elif ch==3: INCREASEHRA()
elif ch==4:
newcolumn()
elif ch==5: deletcolumn()
elif ch==0: print("Exiting Menu")
else: print ("choice is invalid")

You might also like