Not sure if this question is related to Azure Databricks. Since, I am using Azure Databricks and I faced the same issue, I am sharing my answer. Be it pyodbc or jdbc, for my case all these libraries were slow.
Came across "sql-spark-connector" which is about 15 times faster than the generic JDBC connector for writing data to SQL Server.
I am using this connector to load around 140 tables with more than 10 tables having 5 million+ rows. All of these tables are imported in less than 30 mins(Since I have 100 tables, I am multithreading). So it should be minutes to import a single big table.
Here is the code to write the dataframe to SQL.
jdbcUrl = "jdbc:sqlserver://yourSQLServer:1433;database=yourDatabase"
user = "sqlusername"
password = "sqluserpassword"
tName ="yourTableName"
df.write.format("com.microsoft.sqlserver.jdbc.spark").mode("overwrite").option(
"reliabilityLevel", "BEST_EFFORT"
).option("tableLock", "false").option("schemaCheckEnabled", "false").option(
"truncate", "true"
).option(
"url", jdbcUrl
).option(
"dbtable", tName
).option(
"nullValue", ""
).option(
"batchsize", 1048576
).option(
"user", user
).option(
"password", password
).save()
You can also refer the sql-spark-connector page to get more samples and details here - sql-spark-connector
Hope it helps!