从 Azure Databricks 删除 SQL 数据库中的表 [英] Drop Table in SQL Database from Azure Databricks

查看:79
本文介绍了从 Azure Databricks 删除 SQL 数据库中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Azure Databricks (PySpark) 在 SQL 数据库中删除一个表.

I need to drop a table in SQL Database using Azure Databricks (PySpark).

我必须不使用 PySpark 之外的任何东西来实现这一点.这可以通过使用 DataFrameWriter 来完成吗?下面的代码(内部我相信)首先删除表,然后创建一个具有相同名称的新表,然后将数据帧数据写入表中.

I am required to not use anything outside PySpark to achieve this. Can this be done to using DataFrameWriter. Below code (internally I believe) first deletes the table and then creates a new table with the same name and then writes the dataframe data into the table.

MyDataFrame.write.format("jdbc").option("url", "jdbc:sqlserver://<SQLServerHost>.windows.net:1433").option("database", 'MyDBName').option("dbtable", 'MyTableName').option("user", "MyUsername").option("password", "MyPassword").mode('overwrite').save()

我想简单地完全删除表格.有没有代码可以做同样的事情?

I want to simply delete the table completely. Is there a code to do the same?

问候,斯雷

推荐答案

df = spark.read.format('jdbc')\
.option("url", "jdbc:sqlserver://MyServerName:MyPort")\
.option("database", 'MyDBName')\
.option("user", "MyUser")\
.option("password", "MyPassword")\
.option('query', 'drop table tablename')

这成功了.

这篇关于从 Azure Databricks 删除 SQL 数据库中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆