# Patterns for using Stored Procedures

**URL:** <https://discourse.getdbt.com/t/patterns-for-using-stored-procedures/10334>\
**Category:** In-Depth Discussions\
**Tags:** best-practice\
**Created:** [October 13, 2023, 6:38pm UTC](https://discourse.getdbt.com/t/patterns-for-using-stored-procedures/10334 "2023-10-13T18:38:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregology](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/gregology/32/2071_2.png) [@gregology](https://discourse.getdbt.com/u/gregology)\
**Post date:** [October 13, 2023, 6:38pm UTC](https://discourse.getdbt.com/t/patterns-for-using-stored-procedures/10334/1 "2023-10-13T18:38:14Z")

</div>

I want to introduce some stored procedures and have their code version controlled within dbt. Ideally dbt would `CREATE OR REPLACE` all of the stored procedures when it deploys to implement any updates.

Are there any established best practices for using stored procedures in dbt?

One solution would be to create a macro that generates the stored procedure but ideally I would like the stored procedures to exist in the database so they could be utilized by users doing ad-hoc queries.
