Skip to main content

Microsoft SQL Server Reference

Authentication options and data type handling for SQL Server connections.

Authentication

VariableExampleDescription
DATACONTRACT_SQLSERVER_AUTHENTICATIONsqlsql (default), cli (uses az login), windows, ActiveDirectoryPassword, ActiveDirectoryServicePrincipal, ActiveDirectoryInteractive
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 through the Azure default credential chain and requires ODBC Driver 18.1 or newer. host, port, database, schema, and driver come from the contract's servers block.

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)