How to connect SQLServer to dbt in PostgreSQL

Galaxy Glossary

How do I connect Microsoft SQL Server to dbt?

Configures dbt to run models against a Microsoft SQL Server database by adding a SQLServer profile and required adapter.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Table of Contents

What prerequisites are required?

Install Python 3.8+, dbt-core ≥1.6, and the SQL Server adapter: pip install dbt-sqlserver. Make sure the target database allows TCP connections and that the service account has CREATE TABLE permission.

How do I add SQL Server to profiles.yml?

Create or open ~/.dbt/profiles.yml. Add a profile name (e.g., sqlserver_ecommerce) and a target (e.g., dev) using the syntax shown below.Save the file and keep credentials secure with environment variables when possible.

Which adapter parameters are mandatory?

You must specify type, driver, server, port, database, schema, user, and password. Optional fields such as encrypt or trust_cert enhance security.

How do I test the connection?

Run dbt debug --target dev --profile sqlserver_ecommerce. A successful run confirms network reachability, authentication, and permission to query system tables.

How do I reference the connection in models?

Switch to your dbt project directory.Use dbt run --target dev --profile sqlserver_ecommerce to compile and materialize models in SQL Server. Jinja macros, ref(), and source() all work identically.

Best practices for SQL Server + dbt

Keep development and production targets isolated. Use dedicated schemas such as analytics_dev and analytics_prod. Leverage incremental models for large fact tables and always define unique keys to avoid full-table rebuilds.

.

Why How to connect SQLServer to dbt in PostgreSQL is important

How to connect SQLServer to dbt in PostgreSQL Example Usage


-- models/revenue_by_customer.sql
SELECT
    c.id            AS customer_id,
    c.name          AS customer_name,
    SUM(o.total_amount) AS lifetime_value
FROM  AS c
JOIN     AS o ON o.customer_id = c.id
GROUP BY c.id, c.name;

How to connect SQLServer to dbt in PostgreSQL Syntax


profiles.yml example:

sqlserver_ecommerce:
  target: dev
  outputs:
    dev:
      type: sqlserver
      driver: "ODBC Driver 18 for SQL Server"
      server: "sql-prod.company.com"
      port: 1433
      database: "ecommerce"
      schema: "analytics_dev"
      user: "dbt_runner"
      password: ""
      encrypt: true
      trust_cert: false
      threads: 4

Common Mistakes

Frequently Asked Questions (FAQs)

Can I use Windows Authentication?

Yes. Omit user and password, then add authentication: windows. Ensure the dbt runner has proper domain rights.

Does dbt support Azure SQL?

Absolutely. Use the same adapter, set encrypt: true, and configure trust_cert as recommended by Microsoft.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.