CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

Interface of Python with SQL Database (4 Marks Questions)

  1. The ‘STUDENT’ table is stored in the database ‘SCHOOL’ in MySQL. The database credentials includes host as ‘localhost’, user as ‘root’ and password as ‘cloud’.  Write python script to do the following:
    • Import necessary modules to establish MySQL connectivity with Python
    • Write a statement to establish connection to the database using given credentials
    • Check the connectivity, whether connection OK or NOT OK.
    • Write python statement to create a cursor object
    • Write python statement to close the connection
  2. Solve the following questions:
    • In a school, a database named “school” is created in mysql whose password is “cbse”. Smith is trying to add a new record of a student havingdetails(3,’Michelle’,’Agartala’) in a“student”table.
    • Write the code in python to read the contents of “number.csv” file consisting of data from a mysql table and print the data of the table on the screen in tabular form of the table.
  3. Write a Python to MySQL connectivity script that deletes records from “Orders” table database “Shop” where price < 400.

No comments:

Post a Comment