0% found this document useful (0 votes)
15 views2 pages

Pymysql Emp Table

Sql

Uploaded by

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

Pymysql Emp Table

Sql

Uploaded by

aaditya160807
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

8/7/24, 9:06 PM Pastebin.com - #1 paste tool since 2002!

import pymysql
db1=pymysql.connect(host='localhost',user='root',password='1234')
cur=db1.cursor()
cur.execute('use abhinavmohak;')
cur.execute('select * from emp;')
result=cur.fetchall()
from tabulate import tabulate
headers = [desc[0] for desc in cur.description]
print(tabulate(result, headers=headers, tablefmt="pretty"))
print('''1.insert new records
2.delete record
3.update record
4.search in table
5.view table
6.exit program''')
while True:
ch=int(input('enter your choice '))
if ch==1:
sno=int(input('enter sno '))
name=input('enter name ')
date=input('enter date of join ')
sal=int(input('enter salary '))
post=input('enter post')
query="insert into emp values('%d','%s','%s','%d','%s');"%(sno,name,date,sal,post)
cur.execute(query)
db1.commit()
elif ch==2:
sno=int(input('enter sno '))
query="delete from emp where sno='%d'"%(sno)
cur.execute(query)
db1.commit()
elif ch==3:
print('''1.update name
2.update salary
3.update post
4.do other operations''')
while True:
choice=int(input('enter what is to be changed '))
if choice==1:
sno=int(input('enter sno' ))
name=input('enter new name ')
query="update emp set name='%s' where sno='%d'"%(name,sno)
cur.execute(query)
db1.commit()
elif choice==2:
sno=int(input('enter sno '))
sal=int(input('enter new salary '))
query="update emp set salary='%d' where sno='%d'"%(sal,sno)
elif choice==3:
sno=int(input('enter sno '))
post=input('enter new post ')
query="update emp set post='%s' where sno='%d'"%(post,sno)
elif choice==4:
break
else:
print('invalid choice')

elif ch==4:
name=input('enter the name you want to search in the table ')
query='select name from emp;'
cur.execute(query)
names=cur.fetchall()
i=0
for k in names:
if (k[i]==name):
print('yes the name is present ')
elif ch==5:
cur.execute('select * from emp;')
https://pastebin.com 1/2
8/7/24, 9:06 PM Pastebin.com - #1 paste tool since 2002!
result=cur.fetchall()
from tabulate import tabulate
headers = [desc[0] for desc in cur.description]
print(tabulate(result, headers=headers, tablefmt="pretty"))

elif ch==6:
print('BYE')
break

https://pastebin.com 2/2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy