INTERFACE PYTHON WITH SQL VIVA

1. What is the role of the execute() method in Python SQL interface?
Answer:
The execute() method is used to run a SQL query. It can be used for SELECT, INSERT, UPDATE, DELETE, or any other SQL command.
 
2. Explain how to update records in an SQL database using Python.
Answer:
To update records, you can use the UPDATE SQL command within the execute() method, followed by commit() to save the changes.
3. What is the difference between fetchall() and fetchone() in Python SQL interface?
Answer:
  • fetchall(): Returns all rows of the result set as a list of tuples.
  • fetchone(): Returns only the first row of the result set as a tuple.
4. How do you close the connection to an SQL database in Python?
Answer:
You can use the close() method of the connection object to close the connection to the database.
5. What is a cursor in the context of Python and SQL?
Answer:
A cursor is an object in Python that allows interaction with the SQL database. It is used to execute SQL queries and fetch results.

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.