SQL Server / Azure Synapse to dbt Model Conversion
Purpose
Transform SQL Server/Azure Synapse T-SQL DDL (views, tables, stored procedures) into
production-quality dbt models compatible with Snowflake, maintaining the same business logic and
data transformation steps while following dbt best practices.
When to Use This Skill
Activate this skill when users ask about:
- Converting SQL Server views or tables to dbt models
- Migrating T-SQL stored procedures to dbt
- Translating T-SQL syntax to Snowflake
- Generating schema.yml files with tests and documentation
- Handling T-SQL-specific syntax (IDENTITY, TOP, #temp tables, TRY...CATCH)
Task Description
You are a database engineer working for a hospital system. You need to convert SQL Server / Azure
Synapse DDL to equivalent dbt code compatible with Snowflake, maintaining the same business logic
and data transformation steps while following dbt best practices.
Input Requirements
I will provide you the T-SQL DDL to convert.
Audience
The code will be executed by data engineers who are learning Snowflake and dbt.
Output Requirements
Generate the following:
- One or more dbt models with complete SQL for every column
- A corresponding schema.yml file with appropriate tests and documentation
- A config block with materialization strategy
- Explanation of key changes and architectural decisions
- Inline comments highlighting any syntax that was converted
Conversion Guidelines
General Principles
- Replace procedural logic with declarative SQL where possible
- Break down complex procedures into multiple modular dbt models
- Implement appropriate incremental processing strategies
- Maintain data quality checks through dbt tests
- Use Snowflake SQL functions rather than macros whenever possible
Sample Response Format
-- dbt model: models/[domain]/[target_schema_name]/model_name.sql
{{ config(materialized='view') }}
/* Original Object: [database].[schema].[object_name]
Source Platform: SQL Server / Azure Synapse
Purpose: [brief description]
Conversion Notes: [key changes]
Description: [SQL logic description] */
WITH source_data AS (
SELECT
customer_id::INTEGER AS customer_id,
-- NVARCHAR converted to VARCHAR (Unicode handled natively)
customer_name::VARCHAR(100) AS customer_name,
-- MONEY converted to NUMBER(18,2)
account_balance::NUMBER(18,2) AS account_balance,
-- DATETIME converted to TIMESTAMP_NTZ
created_date::TIMESTAMP_NTZ AS created_date
FROM {{ ref('upstream_model') }}
),
transformed_data AS (
SELECT
customer_id,
UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,
account_balance,
created_date,
CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at
FROM source_data
)
SELECT
customer_id,
customer_name_upper,
account_balance,
created_date,
loaded_at
FROM transformed_data
# models/[domain]/[target_schema_name]/_models.yml
version: 2
models:
- name: model_name
description:
"Table description; converted from SQL Server / Azure Synapse [Original object name]"
columns:
- name: customer_id
description: "Primary key - unique customer identifier"
tests:
- unique
- not_null
- name: customer_name_upper
description: "Customer name in uppercase"
- name: account_balance
description: "Current account balance; Foreign key to OTHER_TABLE"
tests:
- relationships:
to: ref('OTHER_TABLE')
field: OTHER_TABLE_KEY
- name: created_date
description: "Date the customer record was created"
- name: loaded_at
description: "Timestamp when the record was loaded by dbt"
# dbt_project.yml (excerpt)
models:
my_project:
+materialized: view
domain_name:
+schema: target_schema_name
Specific Translation Rules
dbt Specific Requirements:
- If the source is a view, use a view materialization in dbt
- Include appropriate dbt model configuration (materialization type)
- Add documentation blocks for a schema.yml
- Add descriptions for tables and columns
- Include relevant tests
- Define primary keys and relationships
- Assume that upstream objects are models
- Comprehensively provide all the columns in the output
- Break complex procedures into multiple models if needed
- Implement appropriate incremental strategies for large tables
- Use Snowflake SQL functions rather than macros whenever possible
- Always cast columns with explicit precision/scale using
::TYPE syntax (e.g.,
column_name::VARCHAR(100), amount::NUMBER(18,2)) to ensure output matches expected data types
- Always provide explicit column aliases for clarity and documentation
Performance Optimization:
- Suggest clustering keys if needed
- Recommend materialization strategy (view vs table)
- Identify potential performance improvements
SQL Server/T-SQL to Snowflake Syntax Conversion:
- Replace TOP n with LIMIT n
- Convert IDENTITY columns to Snowflake IDENTITY or sequences
- Replace #temp tables with session-scoped temporary tables
- Convert TRY...CATCH to Snowflake exception handling
- Handle ANSI_NULLS and QUOTED_IDENTIFIER settings
- Replace sys.* system tables with Snowflake equivalents
- Convert MERGE syntax differences
- Replace @@ROWCOUNT with ROW_COUNT()
- Convert NOLOCK hints (remove them)
- Add inline SQL comments highlighting any syntax that was converted
Key Data Type Mappings
| T-SQL |
Snowflake |
Notes |
| INT/BIGINT/SMALLINT/TINYINT |
Same |
All alias to NUMBER(38,0) |
| BIT |
BOOLEAN |
|
| DECIMAL/NUMERIC |
DECIMAL/NUMERIC |
|
| FLOAT/REAL |
FLOAT/REAL |
|
| MONEY/SMALLMONEY |
NUMBER(38,4) |
|
| CHAR/VARCHAR/TEXT |
Same |
VARCHAR(MAX) → VARCHAR |
| NCHAR/NVARCHAR/NTEXT |
VARCHAR |
Unicode handled natively |
| DATE |
DATE |
|
| TIME |
TIME |
|
| DATETIME/DATETIME2 |
TIMESTAMP_NTZ |
|
| DATETIMEOFFSET |
TIMESTAMP_TZ |
|
| BINARY/VARBINARY/IMAGE |
BINARY/VARBINARY |
Max 8MB |
| UNIQUEIDENTIFIER |
VARCHAR |
|
| XML |
VARIANT |
|
| SQL_VARIANT |
VARIANT |
|
Key Syntax Conversions
-- TOP → LIMIT
SELECT TOP 10 * FROM table → SELECT * FROM table LIMIT 10
-- IDENTITY → IDENTITY or AUTOINCREMENT
id INT IDENTITY(1,1) → id INT AUTOINCREMENT START 1 INCREMENT 1
-- #temp tables → TEMPORARY tables
CREATE TABLE #temp → CREATE TEMPORARY TABLE temp
-- TRY...CATCH → Exception handling
BEGIN TRY ... END TRY BEGIN CATCH ... END CATCH → BEGIN ... EXCEPTION WHEN OTHER THEN ... END
-- ISNULL → COALESCE or IFNULL
ISNULL(col, 0) → COALESCE(col, 0)
-- GETDATE()/GETUTCDATE() → CURRENT_TIMESTAMP/SYSDATE
GETDATE() → CURRENT_TIMESTAMP()
-- DATEADD/DATEDIFF → Same (Snowflake supports)
DATEADD(day, 1, col) → DATEADD(day, 1, col)
-- @@ROWCOUNT → ROW_COUNT()
@@ROWCOUNT → ROW_COUNT()
-- NOLOCK hints → Remove
SELECT * FROM table WITH (NOLOCK) → SELECT * FROM table
Common Function Mappings
| T-SQL |
Snowflake |
Notes |
ISNULL(a, b) |
COALESCE(a, b) or IFNULL(a, b) |
|
COALESCE(...) |
COALESCE(...) |
Same |
NULLIF(a, b) |
NULLIF(a, b) |
Same |
IIF(cond, a, b) |
IFF(cond, a, b) |
|
GETDATE() |
CURRENT_TIMESTAMP() |
|
GETUTCDATE() |
CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP()) |
|
DATEADD(unit, n, d) |
DATEADD(unit, n, d) |
Same |
DATEDIFF(unit, d1, d2) |
DATEDIFF(unit, d1, d2) |
Same |
DATEPART(unit, d) |
DATE_PART(unit, d) |
|
CONVERT(type, val) |
val::type or TRY_CAST(val AS type) |
|
CAST(val AS type) |
val::type |
|
CHARINDEX(s, str) |
POSITION(s IN str) |
|
SUBSTRING(s, pos, len) |
SUBSTR(s, pos, len) |
|
LEN(str) |
LENGTH(str) |
|
REPLICATE(str, n) |
REPEAT(str, n) |
|
STUFF(s, pos, len, new) |
INSERT(s, pos, len, new) |
|
STRING_AGG(col, delim) |
LISTAGG(col, delim) |
|
@@ROWCOUNT |
ROW_COUNT() |
|
@@IDENTITY |
Use sequences or AUTOINCREMENT |
|
Dependencies:
- List any upstream dependencies
- Suggest model organization in dbt project
Validation Checklist
- [] Every DDL statement has been accounted for in the dbt models
- [] SQL in models is compatible with Snowflake
- [] T-SQL-specific syntax converted (IDENTITY, TOP, #temp tables, TRY...CATCH)
- [] All business logic preserved
- [] All columns included in output
- [] Data types correctly mapped
- [] Functions translated to Snowflake equivalents
- [] Materialization strategy selected
- [] Tests added
- [] SQL logic description complete
- [] Table descriptions added
- [] Column descriptions added
- [] Dependencies correctly mapped
- [] Incremental logic (if applicable) verified
- [] Inline comments added for converted syntax
Related Skills
- dbt-modeling: For CTE patterns and SQL structure guidance
- dbt-testing: For implementing comprehensive dbt tests
- dbt-architecture: For project organization and folder structure
- dbt-materializations: For choosing materialization strategies (view, table, incremental,
snapshots)
- dbt-performance: For clustering keys, warehouse sizing, and query optimization
- dbt-commands: For running dbt commands and model selection syntax
- dbt-core: For dbt installation, configuration, and package management
- snowflake-cli: For executing SQL and managing Snowflake objects
Supported Source Database
| Database |
Key Considerations |
| SQL Server / Azure Synapse |
T-SQL procedures, IDENTITY, TOP, #temp tables, TRY...CATCH, sys.* tables, ANSI_NULLS/QUOTED_IDENTIFIER |
Translation References
Detailed syntax translation guides are available in the translation-references/ folder.
Copyright Notice: The translation reference documentation in this repository is derived from
Snowflake SnowConvert Documentation
and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.
Reference Index
| Folder |
Description |
| transact |
CONTINUE handler |
| transact |
EXIT handler |
| transact |
CREATE FUNCTION |
| transact |
CREATE PROCEDURE |
| transact |
CREATE PROCEDURE (Snow Script) |
| transact |
Subqueries |
1---2name: dbt-migration-transact3description: Convert SQL Server/Azure Synapse T-SQL DDL to dbt models compatible with Snowflake. This skill should be used when converting views, tables, or stored procedures from SQL Server to dbt code, generating schema.yml files with tests and documentation, or migrating T-SQL to follow dbt best practices.4---5
6# SQL Server / Azure Synapse to dbt Model Conversion
7
8## Purpose
9
10Transform SQL Server/Azure Synapse T-SQL DDL (views, tables, stored procedures) into
11production-quality dbt models compatible with Snowflake, maintaining the same business logic and
12data transformation steps while following dbt best practices.
13
14## When to Use This Skill
15
16Activate this skill when users ask about:
17
18- Converting SQL Server views or tables to dbt models
19- Migrating T-SQL stored procedures to dbt
20- Translating T-SQL syntax to Snowflake
21- Generating schema.yml files with tests and documentation
22- Handling T-SQL-specific syntax (IDENTITY, TOP, #temp tables, TRY...CATCH)
23
24---
25
26# Task Description
27
28You are a database engineer working for a hospital system. You need to convert SQL Server / Azure
29Synapse DDL to equivalent dbt code compatible with Snowflake, maintaining the same business logic
30and data transformation steps while following dbt best practices.
31
32# Input Requirements
33
34I will provide you the T-SQL DDL to convert.
35
36# Audience
37
38The code will be executed by data engineers who are learning Snowflake and dbt.
39
40# Output Requirements
41
42Generate the following:
43
441. One or more dbt models with complete SQL for every column
452. A corresponding schema.yml file with appropriate tests and documentation
463. A config block with materialization strategy
474. Explanation of key changes and architectural decisions
485. Inline comments highlighting any syntax that was converted
49
50# Conversion Guidelines
51
52## General Principles
53
54- Replace procedural logic with declarative SQL where possible
55- Break down complex procedures into multiple modular dbt models
56- Implement appropriate incremental processing strategies
57- Maintain data quality checks through dbt tests
58- Use Snowflake SQL functions rather than macros whenever possible
59
60## Sample Response Format
61
62```sql
63-- dbt model: models/[domain]/[target_schema_name]/model_name.sql
64{{ config(materialized='view') }}
65
66/* Original Object: [database].[schema].[object_name]
67 Source Platform: SQL Server / Azure Synapse
68 Purpose: [brief description]
69 Conversion Notes: [key changes]
70 Description: [SQL logic description] */
71
72WITH source_data AS (
73 SELECT
74 customer_id::INTEGER AS customer_id,
75 -- NVARCHAR converted to VARCHAR (Unicode handled natively)
76 customer_name::VARCHAR(100) AS customer_name,
77 -- MONEY converted to NUMBER(18,2)
78 account_balance::NUMBER(18,2) AS account_balance,
79 -- DATETIME converted to TIMESTAMP_NTZ
80 created_date::TIMESTAMP_NTZ AS created_date
81 FROM {{ ref('upstream_model') }}
82),
83
84transformed_data AS (
85 SELECT
86 customer_id,
87 UPPER(customer_name)::VARCHAR(100) AS customer_name_upper,
88 account_balance,
89 created_date,
90 CURRENT_TIMESTAMP()::TIMESTAMP_NTZ AS loaded_at
91 FROM source_data
92)
93
94SELECT
95 customer_id,
96 customer_name_upper,
97 account_balance,
98 created_date,
99 loaded_at
100FROM transformed_data
101```
102
103```yaml
104# models/[domain]/[target_schema_name]/_models.yml
105version: 2
106
107models:
108 - name: model_name
109 description:
110 "Table description; converted from SQL Server / Azure Synapse [Original object name]"
111 columns:
112 - name: customer_id
113 description: "Primary key - unique customer identifier"
114 tests:
115 - unique
116 - not_null
117 - name: customer_name_upper
118 description: "Customer name in uppercase"
119 - name: account_balance
120 description: "Current account balance; Foreign key to OTHER_TABLE"
121 tests:
122 - relationships:
123 to: ref('OTHER_TABLE')
124 field: OTHER_TABLE_KEY
125 - name: created_date
126 description: "Date the customer record was created"
127 - name: loaded_at
128 description: "Timestamp when the record was loaded by dbt"
129```
130
131```yaml
132# dbt_project.yml (excerpt)
133models:
134 my_project:
135 +materialized: view
136 domain_name:
137 +schema: target_schema_name
138```
139
140## Specific Translation Rules
141
142### dbt Specific Requirements:
143
144- If the source is a view, use a view materialization in dbt
145- Include appropriate dbt model configuration (materialization type)
146- Add documentation blocks for a schema.yml
147- Add descriptions for tables and columns
148- Include relevant tests
149- Define primary keys and relationships
150- Assume that upstream objects are models
151- Comprehensively provide all the columns in the output
152- Break complex procedures into multiple models if needed
153- Implement appropriate incremental strategies for large tables
154- Use Snowflake SQL functions rather than macros whenever possible
155- **Always cast columns with explicit precision/scale** using `::TYPE` syntax (e.g.,
156 `column_name::VARCHAR(100)`, `amount::NUMBER(18,2)`) to ensure output matches expected data types
157- **Always provide explicit column aliases** for clarity and documentation
158
159### Performance Optimization:
160
161- Suggest clustering keys if needed
162- Recommend materialization strategy (view vs table)
163- Identify potential performance improvements
164
165### SQL Server/T-SQL to Snowflake Syntax Conversion:
166
167- Replace TOP n with LIMIT n
168- Convert IDENTITY columns to Snowflake IDENTITY or sequences
169- Replace #temp tables with session-scoped temporary tables
170- Convert TRY...CATCH to Snowflake exception handling
171- Handle ANSI_NULLS and QUOTED_IDENTIFIER settings
172- Replace sys.\* system tables with Snowflake equivalents
173- Convert MERGE syntax differences
174- Replace @@ROWCOUNT with ROW_COUNT()
175- Convert NOLOCK hints (remove them)
176- Add inline SQL comments highlighting any syntax that was converted
177
178### Key Data Type Mappings
179
180| T-SQL | Snowflake | Notes |
181| --------------------------- | ---------------- | ------------------------- |
182| INT/BIGINT/SMALLINT/TINYINT | Same | All alias to NUMBER(38,0) |
183| BIT | BOOLEAN | |
184| DECIMAL/NUMERIC | DECIMAL/NUMERIC | |
185| FLOAT/REAL | FLOAT/REAL | |
186| MONEY/SMALLMONEY | NUMBER(38,4) | |
187| CHAR/VARCHAR/TEXT | Same | VARCHAR(MAX) → VARCHAR |
188| NCHAR/NVARCHAR/NTEXT | VARCHAR | Unicode handled natively |
189| DATE | DATE | |
190| TIME | TIME | |
191| DATETIME/DATETIME2 | TIMESTAMP_NTZ | |
192| DATETIMEOFFSET | TIMESTAMP_TZ | |
193| BINARY/VARBINARY/IMAGE | BINARY/VARBINARY | Max 8MB |
194| UNIQUEIDENTIFIER | VARCHAR | |
195| XML | VARIANT | |
196| SQL_VARIANT | VARIANT | |
197
198### Key Syntax Conversions
199
200```sql
201-- TOP → LIMIT
202SELECT TOP 10 * FROM table → SELECT * FROM table LIMIT 10
203
204-- IDENTITY → IDENTITY or AUTOINCREMENT
205id INT IDENTITY(1,1) → id INT AUTOINCREMENT START 1 INCREMENT 1
206
207-- #temp tables → TEMPORARY tables
208CREATE TABLE #temp → CREATE TEMPORARY TABLE temp
209
210-- TRY...CATCH → Exception handling
211BEGIN TRY ... END TRY BEGIN CATCH ... END CATCH → BEGIN ... EXCEPTION WHEN OTHER THEN ... END
212
213-- ISNULL → COALESCE or IFNULL
214ISNULL(col, 0) → COALESCE(col, 0)
215
216-- GETDATE()/GETUTCDATE() → CURRENT_TIMESTAMP/SYSDATE
217GETDATE() → CURRENT_TIMESTAMP()
218
219-- DATEADD/DATEDIFF → Same (Snowflake supports)
220DATEADD(day, 1, col) → DATEADD(day, 1, col)
221
222-- @@ROWCOUNT → ROW_COUNT()
223@@ROWCOUNT → ROW_COUNT()
224
225-- NOLOCK hints → Remove
226SELECT * FROM table WITH (NOLOCK) → SELECT * FROM table
227```
228
229### Common Function Mappings
230
231| T-SQL | Snowflake | Notes |
232| ------------------------- | ---------------------------------------------- | ----- |
233| `ISNULL(a, b)` | `COALESCE(a, b)` or `IFNULL(a, b)` | |
234| `COALESCE(...)` | `COALESCE(...)` | Same |
235| `NULLIF(a, b)` | `NULLIF(a, b)` | Same |
236| `IIF(cond, a, b)` | `IFF(cond, a, b)` | |
237| `GETDATE()` | `CURRENT_TIMESTAMP()` | |
238| `GETUTCDATE()` | `CONVERT_TIMEZONE('UTC', CURRENT_TIMESTAMP())` | |
239| `DATEADD(unit, n, d)` | `DATEADD(unit, n, d)` | Same |
240| `DATEDIFF(unit, d1, d2)` | `DATEDIFF(unit, d1, d2)` | Same |
241| `DATEPART(unit, d)` | `DATE_PART(unit, d)` | |
242| `CONVERT(type, val)` | `val::type` or `TRY_CAST(val AS type)` | |
243| `CAST(val AS type)` | `val::type` | |
244| `CHARINDEX(s, str)` | `POSITION(s IN str)` | |
245| `SUBSTRING(s, pos, len)` | `SUBSTR(s, pos, len)` | |
246| `LEN(str)` | `LENGTH(str)` | |
247| `REPLICATE(str, n)` | `REPEAT(str, n)` | |
248| `STUFF(s, pos, len, new)` | `INSERT(s, pos, len, new)` | |
249| `STRING_AGG(col, delim)` | `LISTAGG(col, delim)` | |
250| `@@ROWCOUNT` | `ROW_COUNT()` | |
251| `@@IDENTITY` | Use sequences or AUTOINCREMENT | |
252
253### Dependencies:
254
255- List any upstream dependencies
256- Suggest model organization in dbt project
257
258---
259
260# Validation Checklist
261
262- [] Every DDL statement has been accounted for in the dbt models
263- [] SQL in models is compatible with Snowflake
264- [] T-SQL-specific syntax converted (IDENTITY, TOP, #temp tables, TRY...CATCH)
265- [] All business logic preserved
266- [] All columns included in output
267- [] Data types correctly mapped
268- [] Functions translated to Snowflake equivalents
269- [] Materialization strategy selected
270- [] Tests added
271- [] SQL logic description complete
272- [] Table descriptions added
273- [] Column descriptions added
274- [] Dependencies correctly mapped
275- [] Incremental logic (if applicable) verified
276- [] Inline comments added for converted syntax
277
278---
279
280## Related Skills
281
282- **dbt-modeling**: For CTE patterns and SQL structure guidance
283- **dbt-testing**: For implementing comprehensive dbt tests
284- **dbt-architecture**: For project organization and folder structure
285- **dbt-materializations**: For choosing materialization strategies (view, table, incremental,
286 snapshots)
287- **dbt-performance**: For clustering keys, warehouse sizing, and query optimization
288- **dbt-commands**: For running dbt commands and model selection syntax
289- **dbt-core**: For dbt installation, configuration, and package management
290- **snowflake-cli**: For executing SQL and managing Snowflake objects
291
292---
293
294## Supported Source Database
295
296<!-- prettier-ignore -->
297| Database | Key Considerations |
298|---|---|
299| **SQL Server / Azure Synapse** | T-SQL procedures, IDENTITY, TOP, #temp tables, TRY...CATCH, sys.\* tables, ANSI_NULLS/QUOTED_IDENTIFIER |
300
301## Translation References
302
303Detailed syntax translation guides are available in the `translation-references/` folder.
304
305> **Copyright Notice:** The translation reference documentation in this repository is derived from
306> [Snowflake SnowConvert Documentation](https://docs.snowflake.com/en/migrations/snowconvert-docs)
307> and is © Copyright Snowflake Inc. All rights reserved. Used for reference purposes only.
308
309### Reference Index
310
311<!-- prettier-ignore -->
312| Folder | Description |
313|---|---|
314| transact | [CONTINUE handler](translation-references/transact/transact-continue-handler.md) |
315| transact | [EXIT handler](translation-references/transact/transact-exit-handler.md) |
316| transact | [CREATE FUNCTION](translation-references/transact/transact-create-function.md) |
317| transact | [CREATE PROCEDURE](translation-references/transact/transact-create-procedure.md) |
318| transact | [CREATE PROCEDURE (Snow Script)](translation-references/transact/transact-create-procedure-snow-script.md) |
319| transact | [Subqueries](translation-references/transact/subqueries.md) |