# Microsoft SQL Server

Full MSSQL support with Tiberius driver, including Azure SQL, indexed views, MERGE statements, and SQL Agent jobs.

## Overview

Prax provides comprehensive Microsoft SQL Server support through the Tiberius async driver. This includes Azure SQL Database, Azure SQL Managed Instance, and on-premises SQL Server instances.

🔒

#### Azure Ready

Full Azure SQL support with TLS and AAD authentication

⚡

#### MERGE & OUTPUT

Native upsert with MERGE and RETURNING via OUTPUT

📊

#### SQL Agent

Scheduled jobs via SQL Server Agent integration

## Connection Configuration

Configure your MSSQL connection in `prax.toml`. Supports both SQL authentication and Windows/Azure AD authentication.

## Schema Definition

Use MSSQL-specific data types with the `@db.` attribute.

Prax Type | MSSQL Type | Notes
--- | --- | ---
`String` | `NVARCHAR(255)` | Use @db.NVarChar(Max) for unlimited
`Int` | `INT` | @db.BigInt for larger values
`DateTime` | `DATETIME2` | Higher precision than DATETIME
`Decimal` | `DECIMAL(18,2)` | Configurable precision/scale
`Bytes` | `VARBINARY(MAX)` | Binary data storage

## Indexed Views (Materialized Views)

MSSQL supports indexed views, which are materialized views with a clustered index. They're automatically updated when base tables change.

Note: Indexed views require `SCHEMABINDING` and have restrictions on the types of queries they can contain. Prax automatically handles these requirements.

## MERGE Statement (Upsert)

MSSQL uses the `MERGE` statement for upsert operations, providing atomic insert-or-update functionality.

## OUTPUT Clause (RETURNING)

Get inserted/updated/deleted values back from DML statements using the OUTPUT clause.

## CROSS APPLY (LATERAL Joins)

MSSQL's CROSS APPLY and OUTER APPLY are equivalent to LATERAL joins in PostgreSQL.

## Table Hints & Locking

Control locking behavior with MSSQL table hints.

## SQL Server Agent Jobs

Define and manage scheduled jobs that run on SQL Server Agent.

## AlwaysOn Availability Groups

Configure read replicas and automatic failover with AlwaysOn.

## MSSQL Feature Support

Feature | Status | Notes
--- | --- | ---
Indexed Views | ✅ | Automatic maintenance
MERGE Statement | ✅ | Full upsert support
OUTPUT Clause | ✅ | INSERTED/DELETED access
CROSS/OUTER APPLY | ✅ | Lateral join equivalent
SQL Agent Jobs | ✅ | Scheduled tasks
AlwaysOn | ✅ | HA and read replicas
Row-Level Security | ✅ | Security predicates
Dynamic Data Masking | ✅ | Column masking