Skip to main content

Microsoft SQL Server Reference

Authentication options and data type handling for SQL Server connections.

Server​

servers:
- server: production
type: sqlserver
host: localhost
port: 1433
database: mydb
schema: dbo
driver: ODBC Driver 18 for SQL Server

Authentication​

VariableExampleDescription
DATACONTRACT_SQLSERVER_AUTHENTICATIONsqlsql (default), cli (uses az login), windows, ActiveDirectoryPassword, ActiveDirectoryServicePrincipal, ActiveDirectoryInteractive (Windows only)
DATACONTRACT_SQLSERVER_USERNAMErootUsername (for sql, ActiveDirectoryPassword, ActiveDirectoryInteractive)
DATACONTRACT_SQLSERVER_PASSWORDtoorPassword (for sql and ActiveDirectoryPassword)
DATACONTRACT_SQLSERVER_CLIENT_IDa3cf5d29-...Client ID (for ActiveDirectoryServicePrincipal)
DATACONTRACT_SQLSERVER_CLIENT_SECRETkX9~Qr2Lm...Client secret (for ActiveDirectoryServicePrincipal)
DATACONTRACT_SQLSERVER_TRUST_SERVER_CERTIFICATETrueTrust self-signed certificate
DATACONTRACT_SQLSERVER_ENCRYPTED_CONNECTIONTrueUse SSL
DATACONTRACT_SQLSERVER_DRIVERODBC Driver 18 for SQL ServerODBC driver name

The cli mode reuses an az login session: the CLI fetches an Entra ID access token and hands it to the ODBC driver, so it works on macOS and Linux too; it needs the azure extra (datacontract-cli[sqlserver,azure]). ActiveDirectoryInteractive is only offered by the Microsoft ODBC driver on Windows. host, port, database, schema, and driver come from the contract's servers block; host, port, and database can be overridden with DATACONTRACT_SQLSERVER_HOST, DATACONTRACT_SQLSERVER_PORT, and DATACONTRACT_SQLSERVER_DATABASE.

Deprecated variables​

DeprecatedUse instead
DATACONTRACT_SQLSERVER_TRUSTED_CONNECTIONDATACONTRACT_SQLSERVER_AUTHENTICATION=windows

DATACONTRACT_SQLSERVER_TRUSTED_CONNECTION=true predates DATACONTRACT_SQLSERVER_AUTHENTICATION and selects the same Windows integrated auth. It applies only when DATACONTRACT_SQLSERVER_AUTHENTICATION is unset; setting a mode explicitly always wins, and the ignored flag is logged as a warning.

Data types​

Importing​

datacontract import sql --dialect sqlserver maps DDL types as follows; the normalized SQL type is kept as physicalType.

SQL Server typelogicalType
VARCHAR, NVARCHAR, CHAR, NCHAR, TEXT, NTEXTstring (maxLength for varchar/char)
INT, INTEGER, BIGINT, SMALLINT, TINYINTinteger
NUMERIC, DECIMAL, FLOAT, REAL, MONEYnumber
BITboolean
DATEdate
TIMEtime
DATETIME, DATETIME2, DATETIMEOFFSET, SMALLDATETIMEtimestamp
UNIQUEIDENTIFIERstring (format uuid)
BINARY, VARBINARY, IMAGEstring (format binary)
XMLstring

Testing​

SQL Server supports native type introspection: the declared physicalType is checked against information_schema.columns. varchar and nvarchar are distinct types, as are text and varchar — declare what the column actually is. Timezone/precision variants of the datetime family are interchangeable; length is only enforced when declared (varchar(max) is introspected as such). A physicalType that isn't valid T-SQL falls back to the logical type category comparison.

Logical type mapping​

When no physicalType is declared, the CLI derives the native type from the logicalType — for example in datacontract export sql and the dbt exports. This table is generated from the converter in the CLI's code:

logicalTypeSQL Server type
stringvarchar
integerINT
numbernumeric
booleanbit
datedate
timestampdatetimeoffset
timetime
objectnvarchar(max)
array(not supported)
mapnvarchar(max)
vectorVECTOR(1536)