简体   繁体   中英

How to create a table in databricks from an existing table on SQL

Can someone let me know how to create a table in Azure Databricks from a table that exists on Azure sql server? (assuming Databricks already has a jdbc connection to the sql server).

For example, the following will create a table if it doesn't exist from a location in my datalake.

CREATE TABLE IF NOT EXISTS newDB.MyTable USING delta LOCATION
'/mnt/dblake/BASE/Public/Adventureworks/delta/SalesLT.Product/'

I would like do the same but with the table existing on SQL Server?

Here is the basic solution for creation of an external table over an Azure SQL table
You can take the url (connection string) from the Azure Portal

create table if not exists mydb.mytable
using jdbc
options (url = 'jdbc:sqlserver://mysqlserver.database.windows.net:1433;database=mydb;user=myuser;password=mypassword;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;', dbtable = 'dbo.mytable')

Check the following links for additional options

https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-table-datasource.htmlhttps://spark.apache.org/docs/latest/sql-data-sources-jdbc.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM