0

I want to load the data from a SQL Server table using Databricks Delta live table and pass the value to another notebook

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
bigdata techie
  • 147
  • 1
  • 11

1 Answers1

0

To load the data into Databricks delta live table you can connect Azure SQL database with jdbc driver. Connect to the SQL server and load the database data into a data frame using below code:

Host = "<serverName>.database.windows.net"
Port = 1433
Database = "<databaseName>"
Username = "<userName>"
Password = "<password>"
Driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
table = "<tableName>"
Url = f"jdbc:sqlserver://{Host}:{Port};databaseName={Database}"
df = spark.read.format("jdbc").option("driver", Driver).option("url", Url).option("dbtable", table).option("user", Username).option("password", Password).load() 
df.show()

enter image description here

Write the data frame into delta table using below code:

df.write.format("delta").saveAsTable("<deltaTableName>")

enter image description here

You can pass the above delta table value in your required notebook wherever you want using below code:

df = spark.read.table("delta_student")

enter image description here

Bhavani
  • 1,725
  • 1
  • 3
  • 6