GRADE -
XII
MYSQL-PYTHON
CONNECTIVITY
PRACTICE
QUESTIONS
1. Differentiate between fetchone() and fetchall() methods with suitable example of each .
2. What is a result set?
3. Write the code to insert
multiple records into the table student through Python interface.
4. What is database connectivity?
5. Write the code to display all
the records along with the total number of records from the student table using
Python shell.
6. What are the parameters of mysql.connector.connect() fuction which are set by default.
7. What is the purpose of cursor.rowcount?
8.Write a Python program to create a table named STUDENT in a MySQL database with the following structure:
- RollNo (Primary Key)
- Name (50 characters)
- Marks (Integer)
Sol:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="your_password",
database="school"
)
mycursor = mydb.cursor()
mycursor.execute("
CREATE TABLE student (
id INT PRIMARY KEY,
name VARCHAR(50),
marks INT
)")
print("Table created successfully")
Comments
Post a Comment