Lilly
Lilly

Reputation: 988

Delete or overwrite sql table and views from databricks

I am able to write to sql table as below.

%scala

// WRITE FROM CONFIG
val writeToSQL = Config(Map(
  "url"                    -> url,
  "databaseName"           -> database,
  "dbTable"                -> "tableName",
  "accessToken"            -> accessToken,
  "trustServerCertificate" -> "true",
  "encrypt"                -> "true",
  "connectTimeout"         -> "50",
  "queryTimeout"           -> "50"
))

df.write.mode(SaveMode.Append).sqlDB(writeConfig)

Basically I have SQL table and corresponding view. Every time I do the data refresh (from databricks), I want to delete and write the latest records or overwrite the records in the sql as well as the view.

Please let me know whether these two steps are achievable from databricks notebook?

Upvotes: 0

Views: 508

Answers (1)

F4RZ4D
F4RZ4D

Reputation: 125

You can use something like the following in a sql cell:

%sql
drop table database_1.tableName_1

Upvotes: 2

Related Questions