Skip to main content

Microsoft SQL Server

Setup guideโ€‹


Microsoft ODBC driver for SQL Server must be installed to use this destination. This can't be included with dlts python dependencies so you must installed it separately on your system.

See instructions here to install Microsoft ODBC Driver 18 for SQL Server on Windows, Mac and Linux

Following ODBC drivers are supported:

Create a pipelineโ€‹

1. Initalize a project with a pipeline that loads to MS SQL by running

dlt init chess mssql

2. Install the necessary dependencies for MS SQL by running

pip install -r requirements.txt

or run:

pip install dlt[mssql]

This will install dlt with mssql extra which contains all the dependencies required by the sql server client.

3. Enter your credentials into .dlt/secrets.toml.

Example, replace with your database connection info:

database = "dlt_data"
username = "loader"
password = "<password>"
host = ""
port = 1433
connect_timeout = 15

You can also pass a SQLAlchemy-like database connection:

# keep it at the top of your toml file! before any section starts

To pass credentials directly you can use credentials argument passed to dlt.pipeline or methods.

pipeline = dlt.pipeline(pipeline_name='chess', destination='postgres', dataset_name='chess_data', credentials="mssql://loader:<password>")

Write dispositionโ€‹

All write dispositions are supported

If you set the replace strategy to staging-optimized the destination tables will be dropped and recreated with an ALTER SCHEMA ... TRANSFER. The operation is atomic: mssql supports DDL transactions.

Data loadingโ€‹

Data is loaded via INSERT statements by default. MSSQL has a limit of 1000 rows per INSERT and this is what we use.

Supported file formatsโ€‹

Supported column hintsโ€‹

mssql will create unique indexes for all columns with unique hints. This behavior may be disabled

Syncing of dlt stateโ€‹

This destination fully supports dlt state sync

Data typesโ€‹

MS SQL does not support JSON columns, so JSON objects are stored as strings in nvarchar column.

Additional destination optionsโ€‹

mssql destination does not creates UNIQUE indexes by default on columns with unique hint (ie. _dlt_id). To enable this behavior


You can explicitly set the ODBC driver name:

odbc_driver="ODBC Driver 18 for SQL Server"

dbt supportโ€‹

No dbt support yet

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!


Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub โ€“ it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.