0% found this document useful (0 votes)
22 views4 pages

Interface Programs

The document provides a series of Python functions for interacting with a MySQL database named 'school'. It includes functions to fetch employee records sorted by salary, update an employee's salary, delete an employee record based on user input, create a new database, and create an employee table with specific fields. Each function is accompanied by the necessary MySQL connection details and SQL commands for execution.

Uploaded by

Pruthika Kumaran
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)
22 views4 pages

Interface Programs

The document provides a series of Python functions for interacting with a MySQL database named 'school'. It includes functions to fetch employee records sorted by salary, update an employee's salary, delete an employee record based on user input, create a new database, and create an employee table with specific fields. Each function is accompanied by the necessary MySQL connection details and SQL commands for execution.

Uploaded by

Pruthika Kumaran
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

Question 1

Write a function fetchdata() to display all records in ascending


order of their salary from table employee using mysql connector

Host=localhost
User=root
Password=tiger
Database=school
Answer
Table Employee:
def fetchdata():
import [Link]
mydb = [Link](host = "localhost",
user = "root",
passwd = "tiger",
database = "School")
mycursor = [Link]()
[Link]("select * FROM EMPLOYEE ORDER BY SALARY")
myrecords = [Link]()
for row in myrecords:
print(row)
[Link]()
[Link]()
fetchdata()

Output
(4, 'ABHAY', 'FASHION STUDIES', 45000.0)
(1, 'RAJESH', 'IT', 60000.0)
(2, 'MANOJ KUMAR', 'HISTORY', 65000.0)
(3, 'ANUSHA', 'MARKETING', 70000.0)

Question 2

Write a function display() using interface to increase salary of the


employee, whose name is "MANOJ KUMAR", by 3000.
Host=localhost
User=root
Password=tiger
Database=school
Answer
def display():
import [Link]
mydb = [Link](host = "localhost",
user = "root",
passwd = "tiger",
database = "School")
mycursor = [Link]()
[Link]("UPDATE employee SET salary =
salary + 3000 WHERE Ename = 'MANOJ KUMAR'")
[Link]()
[Link]()

Question 3

Write a program to delete the employee record whose name is


read from keyboard at execution time.
Host=localhost
User=root
Password=tiger
Database=school

Answer
import [Link]
mydb = [Link](host = "localhost",
user = "root",
passwd = "tiger",
database = "School")
mycursor = [Link]()
employee_name = input("Enter the name of the employee to delete: ")
[Link]("DELETE FROM employee
WHERE ENAME = { }”.format(employee_name))
print([Link], "Record Deleted")

Output
Enter the name of the employee to delete: RAJESH
1 Record Deleted

Question 4

Create a database TESTDB in interface python.


Host=localhost
User=root
Password=tiger
Answer
import [Link]
conn = [Link](host = 'localhost',
user = 'root',
passwd = 'tiger')
cursor = [Link]()
[Link]("CREATE DATABASE TESTDB")
[Link]()
[Link]()

Question 5

Write a program to create a table EMPLOYEE with Fields


FIRST_NAME, LAST_NAME, AGE, GENDER and INCOME by
using interface.
Host=localhost
User=root
Password=tiger
Database=school

Answer
import [Link]
mydb = [Link](host = 'localhost',
user = 'root',
passwd = 'tiger',
database = "school")
mycursor = [Link]()
[Link]("CREATE table EMPLOYEE (FIRST_NAME VARCHAR(45),
LAST_NAME VARCHAR(45),
AGE INTEGER,
GENDER VARCHAR(10),
INCOME FLOAT)")
[Link]()
[Link]()
[Link]()

Write a function display() using interface to increase salary of the


employee, whose name and salary values are inputted by the
user during execution time.
Host=localhost
User=root
Password=tiger
Database=school

Answer
def display():
import [Link]
mydb = [Link](host = "localhost",
user = "root",
passwd = "tiger",
database = "School")
mycursor = [Link]()
name=input(“Enter the name to update”)
salary=int(input(“Enter a new salary”))
[Link]("UPDATE employee SET salary =
{} + 3000 WHERE Ename = {}".format(salary,name)
[Link]()
[Link]()

You might also like