如何从 SQL 上的现有 table 在数据块中创建 table

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

有人可以告诉我如何从 Azure sql 服务器上存在的 table 在 Azure Databricks 中创建 table 吗? (假设 Databricks 已经与 sql 服务器建立了 jdbc 连接)。

例如,如果我的数据湖中的某个位置不存在,以下内容将创建一个 table。

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

我想做同样的事情,但 table 存在于 SQL 服务器上?

您需要使用 JDBC 驱动程序与 SQL 服务器建立连接并创建 JDBC URL 以便在 Azure [=] 中访问 table 17=]服务器。

更多信息,请查看Establish connectivity to SQL Server

这是在 Azure SQL table
上创建外部 table 的基本解决方案 您可以从 Azure 门户

获取 url(连接字符串)
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')

检查以下链接以获取其他选项

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