英文:
Drop Azure SQL table from Databricks notebook
问题
我正在尝试通过我的 Databricks 笔记本在 Azure SQL Server 数据库中删除一个表(SQL 版本 2019)。
在我的笔记本中,我已经通过 JDBC 连接建立了与 Azure SQL Server 的连接。我有一个测试查询来确认连接。这个工作正常。
然而,我用于在 SQL 数据库中删除表的代码没有失败,但它也没有删除表。表仍然存在。
table_name = "dbo.json_staging"
spark.sql(f"DROP TABLE IF EXISTS {table_name}")
输出:Out[35]: DataFrame[]
英文:
I am trying to drop a table in my Azure SQL server database (SQL version 2019) via my Databricks notebook.
In my notebook, I have established by jdbc connection to the azure sql server. I have a test query to confirm the connection. This works fine.
However, my code to drop a table on the SQL database does not fail but it does not drop the table. The table still exists.
table_name = "dbo.json_staging"
spark.sql(f"DROP TABLE IF EXISTS {table_name}")
Output: Out[35]: DataFrame[]
答案1
得分: 1
我已经尝试使用以下代码在Azure Databricks中从Azure SQL数据库中删除表。
我使用了SCALA语言。
%scala
import java.util.Properties
import java.sql.DriverManager
val jdbcUsername = "admin02"
val jdbcPassword = "Welcome@1"
val driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
val jdbcUrl = s"jdbc:sqlserver://sqlserveraug09.database.windows.net:1433;database=db002;user=admin02@sqlserveraug09;password=Welcome@1;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"
val connectionProperties = new Properties()
connectionProperties.put("user", s"${jdbcUsername}")
connectionProperties.put("password", s"${jdbcPassword}")
connectionProperties.setProperty("Driver", driverClass)
val connection = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword)
val stmt = connection.createStatement()
val sql = "DROP Table employee_new"
stmt.execute(sql)
connection.close()
输出:
我已经删除了名为employee_new的表。
英文:
I have tried the below code to DROP the table from the Azure SQL database Using Azure Databricks.
I have tried it using the SCALA
%scala
import java.util.Properties
import java.sql.DriverManager
val jdbcUsername = "admin02"
val jdbcPassword = "Welcome@1"
val driverClass = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
val jdbcUrl = s"jdbc:sqlserver://sqlserveraug09.database.windows.net:1433;database=db002;user=admin02@sqlserveraug09;password=Welcome@1;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"
val connectionProperties = new Properties()
connectionProperties.put("user", s"${jdbcUsername}")
connectionProperties.put("password", s"${jdbcPassword}")
connectionProperties.setProperty("Driver", driverClass)
val connection = DriverManager.getConnection(jdbcUrl, jdbcUsername, jdbcPassword)
val stmt = connection.createStatement()
val sql = "DROP Table employee_new"
stmt.execute(sql)
connection.close()
Output:
I have DROPED the Table named employee_new
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论