Python-MYSQL Connectivity Board Questions


  1. Sunil wants to write a Program in Python to update the quantity to 20 of the records whose item code is 111 in the table named shop in MySQL database named Keeper. The table shop in MySQL contains the following attributes : [4 MARKS] [2024]

    Item_code : Item code (Integer)
    Item_name : Name of item (String)
    Qty : Quantity of item (Integer)
    Price : Price of item (Integer)

    Consider the following to establish connectivity between Python and MySQL :
    Username : admin
    Password : Shopping
    Host : localhost
  2. COMING SOON

  3. Sumit wants to write a code in Python to display all the details of the passengers from the table flight in MySQL database, Travel. The table contains the following attributes : [4 MARKS] [2024]

    F_code : Flight code (String)
    F_name : Name of flight (String)
    Source : Departure city of flight (String)
    Destination : Destination city of flight (String)

    Consider the following to establish connectivity between Python and MySQL :
    Username : root
    Password : airplane
    Host : localhost
  4. COMING SOON

  5. The code given below reads the record from the table employee and displays only those records who have employees coming from city ‘Delhi’ :
    E_code - String
    E_name - String
    Sal - Integer
    City - String

    Note the following to establish connectivity between Python and MySQL :
    Username is root
    Password is root
    The table exists in a MySQL database named emp.

    The details (E_code, E_name, Sal, City) are the attributes of the table.

    Write the following statements to complete the code :
    Statement 1 - to import the desired library.
    Statement 2 - to execute the query that fetches records of the employees coming from city ‘Delhi’.
    Statement 3 - to read the complete data of the query (row whose city is Delhi) into the object named details, from the table employee in the database. [3 MARKS] [2023]

    import ____________ as mysql      #Statement 1
    
    def display():
        mydb=mysql.connect(host="localhost", user="root", password="root", database="emp")
        mycursor=mydb.cursor()
        ________________________        #Statement 2
        details = __________________      #Statement 3
        for i in details:
              print(i)
    
  6. Statement 1: mysql.connector
    
    Statement 2: mycursor.execute("select * from employee where City='Delhi ' ") 
    
    Statement 3: mycursor.fetchall()
    

  7. The code given below deletes the record from the table employee which contains the following record structure :
    E_code - String
    E_name - String
    Sal - Integer
    City - String

    Note the following to establish connectivity between Python and MySQL :
    Username is root
    Password is root
    The table exists in a MySQL database named emp.

    The details (E_code, E_name, Sal, City) are the attributes of the table.

    Write the following statements to complete the code :
    Statement 1 - to import the desired library.
    Statement 2 - to execute the command that deletes the record with E_code as ‘E101’.
    Statement 3 - to delete the record permanently from the database. [3 MARKS] [2023]

    import ____________ as mysql      #Statement 1
    
    def delete():
        mydb=mysql.connect(host="localhost", user="root", password="root", database="emp")
        mycursor=mydb.cursor()
        __________________      #Statement 2
        __________________      #Statement 3
        print("Record deleted")
    
  8. Statement 1 : mysql.connector 
     
    Statement 2: mycursor.execute("DELETE FROM employee WHERE E_code='E101' ")
    
    Statement 3 : mydb.commit()