简体   繁体   English

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

[英]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?有人可以让我知道如何从 Azure sql 服务器上存在的表在 Azure Databricks 中创建表吗? (assuming Databricks already has a jdbc connection to the sql server). (假设 Databricks 已经与 sql 服务器建立了 jdbc 连接)。

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?我想做同样的事情,但表存在于 SQL 服务器上?

Here is the basic solution for creation of an external table over an Azure SQL table这是在 Azure SQL 表上创建外部表的基本解决方案
You can take the url (connection string) from the Azure Portal您可以从 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')

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 https://spark.apache.org/docs/latest/sql-ref-syntax-ddl-create-table-datasource.htmlhttps://spark.apache.org/docs/latest/sql-data-sources-jdb .html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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