[go: up one dir, main page]

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

INTERFACE

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)
13 views8 pages

INTERFACE

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/ 8

1 (i) Kabir wants to write a program in

Python to insert the following record


in the table named Student in
MYSQL database, SCHOOL:
∙ rno(Roll number )- integer
∙ name(Name) - string
∙ DOB (Date of birth) – Date
∙ Fee – float
Note the following to establish connectivity between
Python and MySQL:
∙ Username - root
Password - tiger
∙ Host - localhost
The values of fields rno, name, DOB and fee has to be
accepted from the user. Help Kabir to write the program in Python.
2
3
4

5 The code given below inserts the following record in the table Student:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named school.
The details (RollNo, Name, Clas and Marks) are to be accepted from the user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table
Student.
Statement 3- to add the record permanently in the database
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root",password="tiger",
database="school")
mycursor=_________________ #Statement 1
rno=int(input("Enter Roll Number :: "))
name=input("Enter name :: ")
clas=int(input("Enter class :: "))
marks=int(input("Enter Marks :: "))
querry="insert into student values({},'{}',{},{})".format(rno,name,clas,marks)
______________________ #Statement 2
______________________ # Statement 3
print("Data Added successfully")

6 The code given below reads the following record from the table named student
and displays only those records who have marks greater than 75:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named school.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the query that extracts records of those students
whose marks are greater than 75.
Statement 3- to read the complete result of the query (records whose
marks are greater than 75) into the object named data, from the table student in
the database.
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root",password="tiger",
database="school")
mycursor=_______________ #Statement 1
print("Students with marks greater than 75 are : ")
_________________________ #Statement 2
data=__________________ #Statement 3
for i in data:
print(i)
print()

7 The code given below inserts the following record in the table Employee:
Empno – integer
EName – string
Desig – integer
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is Password
The table exists in a MYSQL database named Bank.
The details (Empno, Ename, Design and Salary) are to be accepted from the
user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to query string.
Statement 3- to execute insert query for employee table
import mysql.connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='Password',
database='bank')
mycursor=_________________ # statement1
eno=int(input('enter Employee no'))
nm=input('enter Employee name')
d=input('enter Designation)
s=int(input(‘Enter salary’))
rtup=(eno,n,d,s)

rq=’’’insert into Employee (Empno, Ename, Design,Salary) values


(___________________)’’’ #statement2
mycursor.________________ #statement 3
mydb.commit()
print("Data Added successfully"

8 The code given below reads the following record from Table named Employee
and display those record salary >= 30000 and <= 90000:
Empno – integer
EName – string
Desig – integer
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is Password
The table exists in a MYSQL database named Bank.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to query string.
Statement 3- to execute the query that extracts records of those Employees
whose salary >=30000 and <=90000.
import mysql.connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='Password',
database='bank')
mycursor=_________________ # statement1
mycursor.________________ #statement 2
data= __________________ # statement 3
for x in data:
print(x)

9 Write a python connectivity program to insert a record to the


employee table by reading inputs from keyboard at execution time:
Database name: Department Table: Employee
Columns: E_id, Ename, Desig, Salary

10 Write a python connectivity program to delete the employee record


whose employeeid has to be read from keyboard at execution time:
Database name: Department Table: Employee
Columns: E_id, Ename, Desig, Salary

You might also like