Apache Airflow MSSQL Provider

4.5.1 · active · verified Fri Apr 10

The Apache Airflow Microsoft MSSQL Provider enables seamless interaction with Microsoft SQL Server databases within Airflow DAGs. It provides hooks and operators for connecting to, querying, and managing data in MSSQL. This provider is part of the larger Apache Airflow ecosystem, currently at version 4.5.1, and receives updates aligned with Airflow's release cycle, as well as independent bug fixes and feature enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a simple Airflow DAG that uses the `MsSqlOperator` to connect to a Microsoft SQL Server database and execute a basic SQL query. Before running, ensure you have an Airflow connection named `mssql_default` configured with the appropriate host, credentials, and optional driver settings in your Airflow UI or via CLI.

from __future__ import annotations

import pendulum

from airflow.models.dag import DAG
from airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator

# Configure an Airflow Connection named 'mssql_default'
# Host: your_mssql_host
# Port: 1433 (default)
# Schema: your_database_name
# Login: your_username
# Password: your_password
# Extra: {"driver": "ODBC Driver 17 for SQL Server"} (if using pyodbc)

with DAG(
    dag_id="mssql_quickstart_dag",
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    schedule=None,
    catchup=False,
    tags=["mssql", "example"],
) as dag:
    run_simple_query = MsSqlOperator(
        task_id="run_select_statement",
        mssql_conn_id="mssql_default",
        sql="SELECT 1 as result;",
        autocommit=True,
    )

view raw JSON →