Interface Python with MySQL || Important Questions || Class 12 || Sumita-Arora || Preeti-Arora || Computer Science



Q. What is database connectivity?


Q. What is connection? What is its role?


Q. What is a result set?


Q. Which package must be imported in Python to create a database connectivity application?



Q. Write a Python database connectivity script that deletes records from category table of database items that have name = 'Stockable'



Q. Explain the following 'results' retrieval methods with examples.

A. fetchone ()
B. rowcount ()
C. fetchall ()



Q. What is the significance of using connect ()?


Q. What is the role of execute()?


Q. What is Python's database interface known as?


Q. What does database DB-API include?


Q. Explain what the following query will do?

import mysql.connector
db = mysql.connector.connect(….)
cursor = db.cursor()
person_id = input("Enter required person id")
lastname = input("Enter required lastname")
db.execute("INSERT INTO staff (person_id, lastname) VALUES ({}, ‘{}’) ".
format (person_id, lastname))
db.commit()
db.close()



Q. Explain the various database operations one can perform using MySQL-Python connectivity.


Q. Design a Python application to obtain a search criteria from user and then fetch records based on that from empl table. (Given in Book)


Q. Write a program to increase salary of the employee, whose name is "MANOJ KUMAR", by 3000.


Q. Create a database TESTDB.

• Create a table EMPLOYEE with Fields FIRST_NAME, LAST_NAME, AGE, SEX and INCOME in TESTDB.



Q. What will be the generated query string?

query = "INSERT INTO books (title, isbn) VALUES (%s, %s)". ('Ushakaal', '12678987035')



Q. Which record will get inserted in the table by following code?

import mysql.connector as sqltor
mycon = sqltor.connect (host = "localhost", user = "learner", passwd = "fast", database = "test")
cursor = mycon.cursor()
query = "INSERT INTO books (title, isbn) VALUES (%s, %s)".% ('Ushakaal', ‘12678987036’)
cursor.execute(query)
mycon.commit()



Q. What will be the generated query string?

query = "INSERT INTO books(title, isbn) VALUES ('{}', {})". Format('ushakiran', '42568987036')



Q. Which record will get inserted in the table by following code:

import mysql.connector as sqltor
mycon = saltor.connect (host = "localhost", user = "learner", passwd ="fast", database = "test")
cursor = mycon.cursor()
query = "INSERT INTO books (title, isbn) VALUES('()', ())".format(“Ushakiran”, ‘42568987836’)
cursor.execute(query)
mycon.commit()



Q. The books table of test database contains the records shown below:-

Title    ISBN
Die to Live    78127873915
Again?    23686286243
Ushakaal    12678987036
Ushakiran    42568987036

What will be the output produced by following code:
import mysql.connector as sqltor.
conn = sqltor.connect (host = "localhost", user = "learner", passwd = "fast", database = "test")
cursor = conn.cursor()
cursor.execute("SELECT * FROM books")
row = cursor.fetchone()
while row is not None:
    print (row)
    row = cursor.fetchone()



Q. Which file do we import in Python script to establish MySQL-Python connectivity?


Q. What are the features of MySQL?


Q. What are the basic steps to connect with MySQL using table Members?


Q. Explain the benefits of Python Database Programming.


Q. How can we implement MySQL Database?


Q. ABC Infotech Pvt. Ltd. needs to store, retrieve and delete the records of its employees. Develop an interface that provides front-end interaction through Python, and stores and updates records using MySQL.
The operations on MySQL table "emp" involve reading, searching, updating and deleting the records of employees.

(a) Program to read and fetch all the records from EMP table having salary more than 70000.

(b) Program to update the records of employees by increasing salary by 1000 of all those employees who are getting less than 80000.

(c) Program to delete the record on the basis of inputted salary.

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post