Running the Query in SQL from Python

Now that you have established the connection between the SQL server and Python, you can execute SQL queries directly in your Python environment. To do so, you need to define the cursor from the connection. The execute() function is for executing a SQL statement.

cursor = connection.cursor()
cursor.execute("SELECT * FROM Users")
for row in cursor: