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())