> ## Documentation Index
> Fetch the complete documentation index at: https://ngquct-worktree-statusbar-redesign.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft SQL Server

> Connect to SQL Server 2017+ and Azure SQL Database via FreeTDS with T-SQL query support

# Microsoft SQL Server Connections

TablePro connects to SQL Server 2017 and later via FreeTDS. This covers instances on Windows, Linux, Docker, and Azure SQL Database.

<Warning>
  FreeTDS must be built before connecting to SQL Server. Run `scripts/build-freetds.sh` once to compile the required library.
</Warning>

## Quick Setup

Run `scripts/build-freetds.sh` first. Click **New Connection**, select **SQL Server**, enter host/port/credentials/database, and click **Create**.

## Connection Settings

| Field        | Default     | Notes                                                                                                                                                    |
| ------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Host**     | `localhost` |                                                                                                                                                          |
| **Port**     | `1433`      |                                                                                                                                                          |
| **Username** | `sa`        | SQL Server Authentication only (no Windows Auth)                                                                                                         |
| **Database** | -           | Optional. Leave empty to browse all databases. Switch with **Cmd+K**. Required for logins scoped to a single database, such as Azure SQL contained users |

## Example Configurations

**Local**: host `localhost:1433`, user `sa`, database `master`
**Docker**: `mcr.microsoft.com/mssql/server:2022-latest`, env `ACCEPT_EULA=Y`, `SA_PASSWORD` must have uppercase/lowercase/digits/symbols
**Remote**: Standard credentials
**Azure SQL**: Host `server.database.windows.net`, user may need `user@servername` suffix

## Connection URL

```text theme={null}
mssql://user:password@host:1433/database
sqlserver://user:password@host:1433/database
```

See [Connection URL Reference](/databases/connection-urls) for all parameters.

## Features

**Schema Selection**: Default schema is `dbo`. Switch with **Cmd+K**. Shows accessible schemas and tables.

**Table Info**: Columns (types, nullability, defaults), indexes (clustered/non-clustered), foreign keys, DDL with constraints.

**Query Editor** (T-SQL, pagination with OFFSET/FETCH):

```sql theme={null}
-- Paginated results
SELECT *
FROM dbo.orders
ORDER BY order_id
OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY;

-- Row count estimate (fast, uses statistics)
SELECT SUM(p.rows) AS row_count
FROM sys.partitions p
JOIN sys.tables t ON p.object_id = t.object_id
WHERE p.index_id IN (0, 1)
  AND t.name = 'orders';

-- View definition
SELECT OBJECT_DEFINITION(OBJECT_ID('dbo.my_view'));

-- List all tables in the current database
SELECT TABLE_SCHEMA, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_SCHEMA, TABLE_NAME;
```

**Schema Editing** (T-SQL with bracket notation): `ALTER TABLE [dbo].[users] ADD [col] TYPE;` `EXEC sp_rename 'dbo.table.old', 'new', 'COLUMN';` `DROP COLUMN [field];` `CREATE INDEX [IX_name] ON [dbo].[table] ([col]);`

**Foreign Keys**: Displayed in structure. Manual query: `SELECT fk.name FROM sys.foreign_keys fk...`

**Authentication**: SQL Server Authentication only (username/password). No Windows Auth. Create login: `CREATE LOGIN user WITH PASSWORD = 'StrongPassword1!'; CREATE USER user FOR LOGIN user; ALTER ROLE db_datareader ADD MEMBER user;`

## SSL/TLS

TablePro maps the SSL/TLS pane to FreeTDS `DBSETENCRYPT`. FreeTDS dblib accepts four encryption strings; verification beyond the system trust store is configured in `freetds.conf`, not per connection.

| Mode                       | FreeTDS value | Behavior                                                |
| -------------------------- | ------------- | ------------------------------------------------------- |
| **Disabled**               | `off`         | Plain TCP                                               |
| **Preferred**              | `request`     | Try TLS, fall back to plain if the server cannot        |
| **Required (skip verify)** | `require`     | TLS required; cert validated against system trust store |
| **Verify CA**              | `require`     | Same as Required; CA path is not passed through dblib   |
| **Verify Identity**        | `require`     | Same as Required                                        |

For Azure SQL Database, pick **Required** or stricter. For SQL Server 2017+ on a self-signed cert, the system trust store will reject the handshake. To skip verification per connection, override via `freetds.conf` (`tds_check_certificate = no` under the relevant section) or import the server certificate into the macOS keychain.

## Troubleshooting

**Connection refused**: Enable TCP/IP in SQL Server Configuration Manager, verify SQL Server service running, check firewall port 1433, ensure Docker started.

**Login failed**: Verify credentials, check mixed-mode authentication enabled: `SELECT SERVERPROPERTY('IsIntegratedSecurityOnly');` Set to 2 for mixed mode. If the login only has access to one database (an Azure SQL contained user), set the **Database** field. TablePro sends it during login; without it the server authenticates against `master` and rejects the login.

**FreeTDS not found**: Run `scripts/build-freetds.sh` to compile and place library.

**Limitations**: SQL Server Auth only, no Windows Auth, named instances unsupported (use IP:port), NTEXT/TEXT/IMAGE deprecated (use \*MAX types).
