cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
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

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?

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.