0% found this document useful (0 votes)
2 views3 pages

SQL Interconnectivity Code

The document contains Python code for managing an EMPLOYEE database using MySQL, including functionalities to delete and update records in the EMP and DEPT tables. It demonstrates how to connect to the database, execute SQL commands, and commit changes. The code also includes user prompts for inputting employee and department details for deletion and updating records.

Uploaded by

kavyamodem9
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)
2 views3 pages

SQL Interconnectivity Code

The document contains Python code for managing an EMPLOYEE database using MySQL, including functionalities to delete and update records in the EMP and DEPT tables. It demonstrates how to connect to the database, execute SQL commands, and commit changes. The code also includes user prompts for inputting employee and department details for deletion and updating records.

Uploaded by

kavyamodem9
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
You are on page 1/ 3

Select

import mysql.connector

mycon=mysql.connector.connect(host="localhost", user="root", passwd="admin",

database="EMPLOYEE")

mycursor=mycon.cursor()

print("\nBEFORE DELETION CONTENT OF EMP TABLE FOLLOWS: ")

mycursor.execute("SELECT * FROM EMP")

for k in mycursor:

print(k)

eno=int(input("Enter the empno which record you want to delete: "))

qr="DELETE FROM EMP WHERE empno={}".format(eno)

mycursor.execute(qr)

mycon.commit() # To save above DML tansactions to the databases otherwise will

not save permanently

print("\nAFTER DELETION CONTENT OF EMP TABLE FOLLOWS: ")

mycursor.execute("SELECT * FROM EMP")

rec=mycursor.fetchall()

for k in rec:

print(k)

mycon.close()

UPDATE

import mysql.connector

mycon=mysql.connector.connect(host="localhost", user="root",passwd="admin",

database="EMPLOYEE")

mycursor=mycon.cursor()

dno=int(input("Enter the DEPT. NO which record you want to update: "))

qr="SELECT * FROM DEPT WHERE deptno={}".format(dno)

mycursor.execute(qr)
rec=mycursor.fetchall()

print("\n Old Record is follows: ")

for k in rec:

print(k)

print("\nENTER DETAILS TO UPDATE RECORD:\n")

print("Entered DEPTNO No:",dno)

dname=input("Enter Department Name:")

loc=input("Enter Location of the Department:")

qr="UPDATE dept SET dname='{}', loc='{}' WHERE deptno={}".format(dname, loc,

dno)

print(qr)

mycursor.execute(qr)

mycon.commit()

print("\nNEW RECORD AFTER UPDATE OF TABLE: ")

mycursor.execute("SELECT * FROM DEPT")

rec=mycursor.fetchall()

for k in rec:

print(k)

mycon.close()

insert

You might also like