> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sqlbuild.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Server

> Microsoft SQL Server adapter configuration for SQLBuild.

SQL Server requires the optional `pymssql` dependency:

```bash theme={null}
pip install 'sqlbuild[sqlserver]'
# or
uv pip install 'sqlbuild[sqlserver]'
```

## Connection config

```toml theme={null}
adapter = "sqlserver"

[connection]
host = "localhost"
port = 1433
user = "sa"
password = "my_password"
database = "my_database"
```

| Field      | Description                                                                    |
| ---------- | ------------------------------------------------------------------------------ |
| `host`     | SQL Server hostname (default: `localhost`). Also accepts `server` as an alias. |
| `port`     | SQL Server port (default: `1433`)                                              |
| `user`     | Database user (default: `sa`). Also accepts `username` as an alias.            |
| `password` | Database password                                                              |
| `database` | Database name (default: `master`). Also accepts `dbname` as an alias.          |

All fields in `connection` are passed to `pymssql.connect()`. See the [pymssql documentation](https://pymssql.readthedocs.io/en/stable/ref/pymssql.html) for all available options.

## Per-target connections

```toml theme={null}
adapter = "sqlserver"

[connection]
host = "localhost"
user = "sa"
password = "${ENV:MSSQL_PASSWORD}"

[targets.prod]
schema = "prod"

[targets.prod.connection]
host = "prod-sql.example.com"
database = "analytics"

[targets.dev]
schema = "dev"

[targets.dev.connection]
database = "analytics_dev"
```
