Introduction

In dbt, one of the most essential commands is dbt run. In this tutorial, we’ll dive deep into the dbt run command, exploring its syntax, functionality, and practical usage. This tutorial is also a valuable resource for those preparing for the dbt Analytics Engineering Certification Exam.

💡Explanation of dbt run

The dbt run command is a core function in dbt that executes your data models by running the SQL queries defined in your project. It compiles the code in your .sql files, processes the transformations, and materializes the results in your target data warehouse

📝 Basic Syntax

The basic syntax for the dbt run command is the following:

dbt run

When you run this command in your terminal, dbt will run all models in your project by default. It will compile and run the SQL queries defined in each model, transforming the data and materializing the results in your target data warehouse.

⚙️ Specific options

Specific options allow you to customize and control the dbt run command. Let's have a look at 9 different options to specify the dbt run command.

1) Run single model

To run a single model, use the --select flag followed by the model name:

dbt run --select model_name

2) Run multiple models

To run multiple models, use the --select flag followed by the model names:

dbt run --select model_name1 model_name2 model_name3

3) Exclude model

To exclude one or more models from being run, use the --exclude flag followed by the model name(s):

dbt run --exclude model_name

4) Run models within a path

To run all models within a specific path, use the --select flag followed by the path to the models:

dbt run --select path/to/my/models

5) Run model and all its downstream dependencies

To run a specific model and all its downstream dependencies, use the --select flag followed by the model name and the + operator:

dbt run --select model_name+
CTA Image

If you’d like to dive deeper into dbt (data build tool), our book Building Modern Data Pipelines with dbt: From Raw Data to Gold Standard with the Medallion Architecture provides a hands-on guide to designing modern data pipelines. It covers dbt’s core concepts and best practices, including building Bronze, Silver, and Gold layers with the Medallion Architecture. It also serves as a hands-on study guide for the dbt Analytics Engineering Certification.

View on Amazon

6) Run model and all its upstream dependencies

You can view this post with the tier: Academy Membership

Join academy now to read the post and get access to the full library of premium posts for academy members only.

Join Academy Already have an account? Sign In