<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Populating data from databricks to sql server tables in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/populating-data-from-databricks-to-sql-server-tables/m-p/6428#M2577</link>
    <description>&lt;P&gt;@Deepak Bhatt​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, using the Spark Synapse connector could be a good option for upserting data from a Delta table into a SQL Server table. The Spark Synapse connector allows you to read and write data from Azure Synapse Analytics, formerly known as SQL Data Warehouse, and it supports both read and write operations.&lt;/P&gt;&lt;P&gt;To upsert data, you can first read the data from the Delta table using Spark's DataFrame API, and then write the data to the SQL Server table using the Synapse connector's write method. To perform an upsert, you can use the MERGE statement in SQL Server.&lt;/P&gt;&lt;P&gt;Here's some sample code that demonstrates how to use the Spark Synapse connector to upsert data from a Delta table into a SQL Server table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;# Read data from Delta table
delta_df = spark.read.format("delta").load("/path/to/delta/table")
&amp;nbsp;
# Write data to SQL Server table
delta_df.write \
    .format("com.microsoft.sqlserver.jdbc.spark") \
    .mode("overwrite") \
    .option("url", "jdbc:sqlserver://&amp;lt;your_server&amp;gt;:&amp;lt;your_port&amp;gt;;database=&amp;lt;your_database&amp;gt;") \
    .option("dbtable", "&amp;lt;your_table&amp;gt;") \
    .option("user", "&amp;lt;your_username&amp;gt;") \
    .option("password", "&amp;lt;your_password&amp;gt;") \
    .option("tableLock", "true") \
    .option("bulkCopyBatchSize", "100000") \
    .option("bulkCopyTableLock", "true") \
    .option("bulkCopyTimeout", "600") \
    .option("batchsize", "100000") \
    .option("reliabilityLevel", "BEST_EFFORT") \
    .option("tempDir", "/mnt/temp") \
    .option("checkpointLocation", "/mnt/checkpoint") \
    .option("mergeSchema", "true") \
    .option("createTableColumnTypes", "&amp;lt;column_types&amp;gt;") \
    .option("spark.connection.mode", "databricks") \
    .option("spark.databricks.delta.preview.enabled", "true") \
    .option("synapseStorageAccountUrl", "&amp;lt;your_storage_account_url&amp;gt;") \
    .option("synapseStorageAccountAccessKey", "&amp;lt;your_storage_account_access_key&amp;gt;") \
    .option("synapseLinkedServiceName", "&amp;lt;your_linked_service_name&amp;gt;") \
    .option("synapseWorkspaceName", "&amp;lt;your_workspace_name&amp;gt;") \
    .option("upsert", "true") \
    .option("primaryKey", "&amp;lt;your_primary_key&amp;gt;") \
    .save()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Make sure to replace the placeholders with your own values for the SQL Server connection and table details. Also, set the upsert option to true and specify the primary key column(s) using the primaryKey option to perform an upsert.&lt;/P&gt;&lt;P&gt;Note that you may need to adjust the other options based on your specific requirements and environment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2023 01:55:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-04-07T01:55:12Z</dc:date>
    <item>
      <title>Populating data from databricks to sql server tables</title>
      <link>https://community.databricks.com/t5/data-engineering/populating-data-from-databricks-to-sql-server-tables/m-p/6427#M2576</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could any one please suggest what is the best way to populate(Upsert) data from delta table into the sql server table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;we are transforming our data in Databricks and storing data into the delta table. but for reporting purpose we need to populate the data in Sql server table as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what is the best way to to do the data Upsert from delta table to Sql server ? &lt;/P&gt;&lt;P&gt;does spark synapse connector will be the the best option ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 17:34:05 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/populating-data-from-databricks-to-sql-server-tables/m-p/6427#M2576</guid>
      <dc:creator>Mr__D</dc:creator>
      <dc:date>2023-04-04T17:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Populating data from databricks to sql server tables</title>
      <link>https://community.databricks.com/t5/data-engineering/populating-data-from-databricks-to-sql-server-tables/m-p/6428#M2577</link>
      <description>&lt;P&gt;@Deepak Bhatt​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, using the Spark Synapse connector could be a good option for upserting data from a Delta table into a SQL Server table. The Spark Synapse connector allows you to read and write data from Azure Synapse Analytics, formerly known as SQL Data Warehouse, and it supports both read and write operations.&lt;/P&gt;&lt;P&gt;To upsert data, you can first read the data from the Delta table using Spark's DataFrame API, and then write the data to the SQL Server table using the Synapse connector's write method. To perform an upsert, you can use the MERGE statement in SQL Server.&lt;/P&gt;&lt;P&gt;Here's some sample code that demonstrates how to use the Spark Synapse connector to upsert data from a Delta table into a SQL Server table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;# Read data from Delta table
delta_df = spark.read.format("delta").load("/path/to/delta/table")
&amp;nbsp;
# Write data to SQL Server table
delta_df.write \
    .format("com.microsoft.sqlserver.jdbc.spark") \
    .mode("overwrite") \
    .option("url", "jdbc:sqlserver://&amp;lt;your_server&amp;gt;:&amp;lt;your_port&amp;gt;;database=&amp;lt;your_database&amp;gt;") \
    .option("dbtable", "&amp;lt;your_table&amp;gt;") \
    .option("user", "&amp;lt;your_username&amp;gt;") \
    .option("password", "&amp;lt;your_password&amp;gt;") \
    .option("tableLock", "true") \
    .option("bulkCopyBatchSize", "100000") \
    .option("bulkCopyTableLock", "true") \
    .option("bulkCopyTimeout", "600") \
    .option("batchsize", "100000") \
    .option("reliabilityLevel", "BEST_EFFORT") \
    .option("tempDir", "/mnt/temp") \
    .option("checkpointLocation", "/mnt/checkpoint") \
    .option("mergeSchema", "true") \
    .option("createTableColumnTypes", "&amp;lt;column_types&amp;gt;") \
    .option("spark.connection.mode", "databricks") \
    .option("spark.databricks.delta.preview.enabled", "true") \
    .option("synapseStorageAccountUrl", "&amp;lt;your_storage_account_url&amp;gt;") \
    .option("synapseStorageAccountAccessKey", "&amp;lt;your_storage_account_access_key&amp;gt;") \
    .option("synapseLinkedServiceName", "&amp;lt;your_linked_service_name&amp;gt;") \
    .option("synapseWorkspaceName", "&amp;lt;your_workspace_name&amp;gt;") \
    .option("upsert", "true") \
    .option("primaryKey", "&amp;lt;your_primary_key&amp;gt;") \
    .save()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Make sure to replace the placeholders with your own values for the SQL Server connection and table details. Also, set the upsert option to true and specify the primary key column(s) using the primaryKey option to perform an upsert.&lt;/P&gt;&lt;P&gt;Note that you may need to adjust the other options based on your specific requirements and environment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2023 01:55:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/populating-data-from-databricks-to-sql-server-tables/m-p/6428#M2577</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-07T01:55:12Z</dc:date>
    </item>
  </channel>
</rss>

