# Executing multiple models via a single sql file

**URL:** <https://discourse.getdbt.com/t/executing-multiple-models-via-a-single-sql-file/12435>\
**Category:** Help\
**Tags:** snowflake, dbt-core\
**Created:** [March 12, 2024, 4:55pm UTC](https://discourse.getdbt.com/t/executing-multiple-models-via-a-single-sql-file/12435 "2024-03-12T16:55:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RP\_007](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@RP\_007](https://discourse.getdbt.com/u/RP_007)\
**Post date:** [March 12, 2024, 4:55pm UTC](https://discourse.getdbt.com/t/executing-multiple-models-via-a-single-sql-file/12435/1 "2024-03-12T16:55:20Z")

</div>

I am an ETL developer, new to dbt.

## The problem I’m having

I want to execute multiple model files through single command.

## The context of why I’m trying to do this

I am trying to build an ETL data pipeline using dbt,snowflake db and azure devops.  
DevOps pipeline will start execution as per schedule.  
Through dbt macro, I gather few variable’s value like countryname.  
and using those, I need to execute around 500 model files.

So instead of writing ‘dbt run -s model1.sql IND, model2.sql IND’(Manually),  
can I create a file(Let’s say **data\_load.sql** ) with all model names in it and then just execute  
**dbt run data\_load.sql**  
from devops pipeline script.

## What I’ve already tried

I have tried writing them in static format like below

 ![image](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/2X/1/134a8da097e7019b24c74081f18632e061f08b3b.png)

Any help for this will be helpful.

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [March 12, 2024, 5:34pm UTC](https://discourse.getdbt.com/t/executing-multiple-models-via-a-single-sql-file/12435/2 "2024-03-12T17:34:44Z")

</div>

you can tag the models and select the tag, or you can write a [https://docs.getdbt.com/reference/node-selection/yaml-selectors|selector](https://docs.getdbt.com/reference/node-selection/yaml-selectors%7Cselector) that selects the right model and use that, in the most complex case that’s basically the same as your request to have a file with the list of what to run

Note: `@Mike Stanley` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1710264878074599?thread_ts=1710262543.961649&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![RP\_007](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@RP\_007](https://discourse.getdbt.com/u/RP_007)\
**Post date:** [March 14, 2024, 6:28am UTC](https://discourse.getdbt.com/t/executing-multiple-models-via-a-single-sql-file/12435/3 "2024-03-14T06:28:13Z")

</div>

Hello @a_slack_user ,

This resolves my problem.  
I just have one thought, this will not execute models in parallel ?  
Also, can we mention any condition in it ?  
like if var a\>var b then

---

<div class="post-metadata">

**Author:** ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)\
**Post date:** [March 14, 2024, 7:26am UTC](https://discourse.getdbt.com/t/executing-multiple-models-via-a-single-sql-file/12435/4 "2024-03-14T07:26:00Z")

</div>

I’m not aware of a way inside dbt to decide to run models or not based on conditions, but you could write a script that decides what to run and then calls dbt.

It will execute as many models in parallel as you have set [https://docs.getdbt.com/docs/running-a-dbt-project/using-threads|threads](https://docs.getdbt.com/docs/running-a-dbt-project/using-threads%7Cthreads) - the main reason to change this value is if your database doesn’t like the number of open connections or simultaneous queries being submitted

Note: `@Mike Stanley` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1710401152881709?thread_ts=1710262543.961649&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [March 21, 2024, 7:26am UTC](https://discourse.getdbt.com/t/executing-multiple-models-via-a-single-sql-file/12435/5 "2024-03-21T07:26:56Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
