title: Spark: optimise writing a DataFrame to SQL Server
body: <p>I am using the code below to write a DataFrame of 43 columns and about 2,000,000 rows into a table in SQL Server:</p>
  
  <pre><code>dataFrame
    .write
    .format("jdbc")
    .mode("overwrite")
    .option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
    .option("url", url)
    .option("dbtable", tablename)
    .option("user", user)
    .option("password", password)
    .save()
  </code></pre>
  
  <p>Sadly, while it does work for small DataFrames it's either extremely slow or gets timed out for large ones. Any hints on how to optimize it?</p>
  
  <p>I've tried setting <code>rewriteBatchedStatements=true</code></p>
  
  <p>Thanks.</p>