# Microsoft SQL Server (MS SQL)

> For the complete documentation index, see [llms.txt](https://kotlin.github.io/dataframe/llms.txt).

Kotlin DataFrame supports reading from a [Microsoft SQL Server (MS SQL)](https://www.microsoft.com/en-us/sql-server) database using JDBC.

API reference: [MsSql](https://kotlin.github.io/dataframe/api-docs/dataframe-jdbc/org.jetbrains.kotlinx.dataframe.io.db/-ms-sql/index.html), [readSqlTable](https://kotlin.github.io/dataframe/api-docs/dataframe-jdbc/org.jetbrains.kotlinx.dataframe.io/read-sql-table.html)

Requires the [dataframe-jdbc module](modules.html#dataframe-jdbc), which is included by default in the general [dataframe artifact](modules.html#dataframe-general) and in [%use dataframe](setupkotlinnotebook.html#integrate-kotlin-dataframe) for Kotlin Notebook.

You’ll also need [the official MS SQL JDBC driver](https://learn.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver17):

Gradle project:

```KOTLIN
dependencies {
    implementation("com.microsoft.sqlserver:mssql-jdbc:$version")
}
```

Kotlin Notebook:

```KOTLIN
USE {
    dependencies("com.microsoft.sqlserver:mssql-jdbc:$version")
}
```

The actual Maven Central driver version can be found [here](https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc).

## Read

A [DataFrame](dataframe.html) can be loaded from a database in several ways:

* a user can read data from a SQL table by a given name ([readSqlTable](readsqldatabases.html)),

* as a result of a user-defined SQL query ([readSqlQuery](readsqldatabases.html)), or

* from a given `ResultSet` ([readResultSet](readsqldatabases.html)). It is also possible to load all data from non-system tables, each into a separate `DataFrame` ([readAllSqlTables](readsqldatabases.html)).

See [Read from SQL databases](readsqldatabases.html) for more details.

```KOTLIN
val url = "jdbc:sqlserver://localhost:1433;databaseName=testDatabase"
val username = "sa"
val password = "password"

val dbConfig = DbConnectionConfig(url, username, password)

val tableName = "Customer"

val df = DataFrame.readSqlTable(dbConfig, tableName)
```

