dbt-sqlserver Adapter

1.9.0 · active · verified Thu Apr 16

dbt-sqlserver is a dbt adapter plugin that enables dbt to connect to and transform data in Microsoft SQL Server databases. It allows users to leverage dbt's powerful data transformation capabilities, including models, tests, and documentation, against SQL Server instances. The library maintains close compatibility with dbt-core's release cycle, typically releasing updates in sync with dbt-core's major versions. The current version is 1.9.0.

Common errors

Warnings

Install

Imports

Quickstart

The primary interaction with dbt-sqlserver is through the dbt CLI and configuration files. This Python snippet demonstrates how to construct the `profiles.yml` content required to connect dbt to a SQL Server database, using environment variables for sensitive or variable settings. After setting up the `profiles.yml` and a dbt project, `dbt debug` is used to verify the connection.

import os

# Configure your SQL Server connection details using environment variables or replace placeholders.
profiles_yml_content = f"""
sqlserver_quickstart:
  target: dev
  outputs:
    dev:
      type: sqlserver
      driver: {os.environ.get('SQLSERVER_ODBC_DRIVER', 'ODBC Driver 17 for SQL Server')} # e.g., 'ODBC Driver 17 for SQL Server' or 'ODBC Driver 18 for SQL Server'
      server: {os.environ.get('SQLSERVER_SERVER', 'localhost')} # e.g., 'your_server_name.database.windows.net' or 'localhost\\SQLEXPRESS'
      port: {os.environ.get('SQLSERVER_PORT', '1433')}
      database: {os.environ.get('SQLSERVER_DATABASE', 'dbt_test_db')}
      schema: {os.environ.get('SQLSERVER_SCHEMA', 'dbt_sqlserver_qs')}
      authentication: {os.environ.get('SQLSERVER_AUTH_METHOD', 'sql')} # 'sql', 'windows', or 'aad'
      # For 'sql' authentication:
      user: {os.environ.get('SQLSERVER_USER', 'your_user_name_here')}
      password: {os.environ.get('SQLSERVER_PASSWORD', 'your_password_here')}
      # For 'aad' or 'windows' authentication, consult dbt-sqlserver documentation.
      # trust_cert: true # Optional: Use with caution if not validating certs
"""

print("To quickly get started with dbt-sqlserver:")
print("1. Ensure you have the appropriate Microsoft ODBC Driver for SQL Server installed on your system.")
print("2. Create or update a file named `profiles.yml` in your `~/.dbt/` directory (or specify with --profiles-dir). ")
print("3. Populate it with content similar to the following (replace placeholders or set environment variables):")
print("\n" + profiles_yml_content)
print("\n4. Initialize a dbt project: `dbt init my_sqlserver_project`")
print("5. In `my_sqlserver_project/dbt_project.yml`, set `profile: sqlserver_quickstart`")
print("6. Navigate into your project directory: `cd my_sqlserver_project`")
print("7. Test your connection: `dbt debug`")

view raw JSON →