title: Databricks - how to write dataframe to SQL Server as Service Principal
body: <p>I can read the data from Azure SQL as Service Principal using Python and Spark.</p>
  <p>How can I write back into Azure SQL table the dataframe using the same tech?</p>
  <p>This is the working code to read data:</p>
  <pre><code>context = adal.AuthenticationContext(authority)
  token = context.acquire_token_with_client_credentials(resource_app_id_url, service_principal_id, service_principal_secret)
  access_token = token[&quot;accessToken&quot;]
  
  Df = spark.read \
               .format(&quot;com.microsoft.sqlserver.jdbc.spark&quot;) \
               .option(&quot;url&quot;, azure_sql_url) \
               .option(&quot;dbtable&quot;, db_table) \
               .option(&quot;databaseName&quot;, database_name) \
               .option(&quot;accessToken&quot;, access_token) \
               .option(&quot;encrypt&quot;, &quot;true&quot;) \
               .option(&quot;hostNameInCertificate&quot;, &quot;*.database.windows.net&quot;) \
               .load()
  </code></pre>