https://learn.microsoft.com
And if we want to use fast_executemany
attribute, we must set cursor.fast_executemany = True
We can modify the sample like this:
import pyodbc
server = <server>.database.windows.net
database = <database>
username = <username>
password = <password>
driver= {ODBC Driver 17 for SQL Server}
cnxn = pyodbc.connect( DRIVER= +driver+ ;SERVER= +server+ ;PORT=1433;DATABASE= +database+ ;UID= +username+ ;PWD= + password)
cursor = cnxn.cursor()
cursor.fast_executemany = True
cursor.execute("SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName FROM [SalesLT].[ProductCategory] pc JOIN [SalesLT].[Product] p ON pc.productcategoryid = p.productcategoryid")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
我认为你可以再次尝试。 如果你仍有其他问题,请让我知道,我将尽力帮助你。
希望能够帮助你们。