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

# SQL Server relation source

> Observe or synchronize a SQL Server table from your app.

Mount `@bijectionhq/app-sql` once per table and pass `provider` as in
the [SQL mount example](https://docs.bijection.com/integrations/native-sql.md#mount-and-bind). Use
`sqlServerRelation("inventory.example:1433", login)` for
ordered observations or `sqlServerChangeTracking("inventory.example:1433", login)`
for change tracking. Initialize each mount as the mount's operator.
Both profiles use the SQL mount’s label.

Seal this JSON for the receiver with `bijection secret set`. Grant the
SQL login `SELECT` on the chosen table, and use a configured TCP port and a
server certificate trusted by the deployment. Enable `ALLOW_SNAPSHOT_ISOLATION`
for the database.

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  "username": "inventory_reader",
  "password": "<database password>",
  "database": "inventory",
  "schema": "dbo",
  "table": "items",
  "key": "id",
  "columns": ["id", "name", "quantity"],
  "incarnation": "inventory-items-1"
}
```

Name one to sixteen distinct columns that SQL Server can serialize with
`FOR JSON PATH`. Rows hold the projected provider JSON text. A row can use
up to 24 KiB of SQL Server JSON storage and each answer carries up to
48 KiB of encoded records. TLS verification uses the fixed endpoint.
The connector refuses server-directed routing.

## Ordered observations

For observations, replace the credential's `key` with the full primary key
in index order, for example `[{"column":"Account","kind":"text"},{"column":"Id","kind":"bigint"}]`.
Use SQL Server 2019 or later and up to eight `bigint`, `varchar` or
`nvarchar` columns. Text uses UTF-8 byte order. Record keys are JSON
arrays of strings, at most 512 encoded bytes.

Each read takes a new snapshot and returns up to 32 rows in full key order.
Later traversals refresh observed keys. The mount keeps keys that cease to
appear. It stops on a changed relation identity until an authorized reset.
Change the configured incarnation after a restore that can reuse the
database or table metadata.

## Change tracking

Use the credential's string `key` and a single `bigint` primary key.
Enable change tracking on the database and table and grant `VIEW CHANGE TRACKING`
on the table. The login needs metadata visibility for the tracked relation
and its internal change-tracking table. Start with a fresh mount for the
selected relation.

The initial snapshot must fit in one answer. Each subsequent read takes one
snapshot, checks the tracking incarnation and minimum valid version, and
reads through the observed database version. A change window must fit in
one answer of at most 32 changed keys. The mount applies upserts or deletes
and commits the new version together. An oversized window leaves the last
published version intact. Change tracking supplies the latest state per
changed key in the window, including deletes.

Health reports the lowest and newest change versions observed in the last
published window as decimal strings. A lost version or changed incarnation
stops polling. Install a fresh mount for the replacement baseline, and
change the configured incarnation after a source restore. The original
mount preserves its last published records for inspection.

## Change data capture

Use `sqlServerCdc({ endpoint: "inventory.example:1433", … })` with its receiver block: `label`, `credential: login`, `requests: { retain, message }`, a reviewed `isolation` statement and a retention budget `hold` (bytes such as `"8GiB"`, or an age). At the budget the source releases its log (`onHold: "release"`), which is a gap, in a
fresh mount. For a protected mount, its `label` is the mount's `data` label. Use the same sealed JSON fields as above
with an additional `"capture_instance": "dbo_items"`.

Enable SQL Server CDC on the database and table. Enable net changes using
the table's single `bigint` primary index. Capture the key and every
projected column, start the provider's capture and cleanup jobs, and give
the login access to the capture instance's gating role and captured
source columns. The connector reads CDC instance and DDL metadata from
`cdc.change_tables` and `cdc.ddl_history`. Its login needs visibility into
the source index and database recovery identity. Use an instance whose
computed or legacy LOB columns are outside the projection.

The first successful read records the captured log head. The mount starts
empty and reports later source commits as SQL Server captures them. Each
page reads one complete source commit for the selected capture instance and
publishes the final operation per key in that commit. Key updates can remove
the old key and add the new one. Inserts and updates publish the captured
row image. Deletes remove the key. Transactions that do not affect this
instance may be skipped. Progress tracks the captured head, which can lag
behind writes to the base table.

The connector reads consecutive LSNs and checks the minimum retained LSN.
The capture identity includes the managed change table and the database's
recovery fork. A lost position, changed capture identity, or captured DDL
stops polling. Each commit must fit 32 changed keys and the encoded result
budget. An oversized commit blocks at its predecessor. Install a fresh
mount to start from a replacement head after an authorized repair.

[SQL Server CDC query functions](https://learn.microsoft.com/en-us/sql/relational-databases/track-changes/work-with-change-data-sql-server)

## Write a declared relation

Follow the [parameterized SQL write guide](https://docs.bijection.com/integrations/native-sql.md#parameterized-sql-writes)
for the writer binding, composite and text keys, declared projection and
provider affected-row evidence.

## Hosted TDS warehouses

Use the same SQL app binding with the warehouse credential and read
contract for [Azure Synapse SQL](https://docs.bijection.com/integrations/native-synapse) or
[Microsoft Fabric Warehouse](https://docs.bijection.com/integrations/native-fabric-warehouse).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.