cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to import a data table from SQLQuery2 into Databricks notebook

moski
New Contributor II

Can anyone show me a few commands to import a table, say "mytable2 

From: Microsoft SQL Server 

Into: Databricks Notebook using spark dataframe or at least pandas dataframe

Cheers!

3 REPLIES 3

irfanaziz
Contributor II

You can read any table from MSSQL. You would need to authenticate to the db, so your would need the connection string:

def dbProps():
 return {
  "user" : "db-user",
  "password" : "your password",
  "driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
 }

So you use the above function to authenticate.

Then read using the below.

url ="jdbc:sqlserver://servername.database.windows.net:1433;database=db-test"
df = spark.read.jdbc(url=url, table="dbo.tablename", properties=dbProps())
 

Aviral-Bhardwaj
Esteemed Contributor III

absolutely right but make sure that you have firewall enabled for SQL server

AviralBhardwaj

Would someone provide example with IntegratedSecurity instead of user name and password?

Is this even possible with Databricks? We do have Azure AD sync'd. Any additional steps to allow IntegratedSecurity in connection string for better security control?

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group