<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi" -->

---
title: SQL Decomposition in a Nutshell | daily.dev
description: Application development principles like decomposition, encapsulation, and statelessness apply just as well to T-SQL as they do to object-oriented code. Using a...
canonical: https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: SQL Decomposition in a Nutshell | daily.dev
og:description: Application development principles like decomposition, encapsulation, and statelessness apply just as well to T-SQL as they do to object-oriented code. Using a...
og:url: https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi
og:image: https://api.daily.dev/og/posts/g5hNRsTpI.png
og:image:alt: SQL Decomposition in a Nutshell
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Decomposition in a Nutshell

**[DevBlogs](https://daily.dev/sources/devblogs)** · 10 min read · 0 upvotes · 0 comments

## Summary

Application development principles like decomposition, encapsulation, and statelessness apply just as well to T-SQL as they do to object-oriented code. Using a hybrid search pipeline (full-text search, vector search, fusion) as a working example, the piece shows how stored procedures act as executable boundaries, user-defined table types serve as reusable DTO-like data shapes, functions eliminate duplicated logic, schemas provide namespacing and security boundaries, and THROW defines explicit failure contracts. It also covers SQL-specific constraints, like INSERT...EXEC not being nestable, and cautions against over-decomposing trivial logic.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://devblogs.microsoft.com/azure-sql/sql-decomposition>

## Questions this post answers

### How can I break a complex hybrid search stored procedure in T-SQL into smaller, testable components?

Split the pipeline into independent stored procedures for full-text search, vector search, and fusion, each with a clear input/output contract. Use a user-defined table type such as a ProductId/Rank shape to pass results between stages, then compose them with a thin orchestrator procedure that calls each in sequence and passes data explicitly as parameters rather than relying on shared session state.

_daily.dev surfaces patterns like this for developers structuring maintainable T-SQL pipelines._

### How do you combine full-text search and vector search results in SQL Server using reciprocal rank fusion?

Convert each retriever's output to a simple 1..N rank rather than comparing raw scores directly, since FREETEXTTABLE ranking and vector distance are not comparable. Apply a reusable function computing 1.0/(60+Rank) to each result set, union the scored rows, then sum scores per ProductId with GROUP BY and order by the summed FusionScore to get the final ranking.

_teams building hybrid search in SQL Server can track fusion techniques like this via daily.dev._

## Similar posts on daily.dev

- [Things I want in a modern relational query language](https://daily.dev/posts/things-i-want-in-a-modern-relational-query-language-y0qgepv3u) · Lobsters · 1 upvotes · 0 comments
- [Escaping the SQL Jungle](https://daily.dev/posts/escaping-the-sql-jungle-gs6fdc3x9) · Towards Data Science · 6 upvotes · 0 comments
- [Anti-Simplification](https://daily.dev/posts/anti-simplification-xcc5kueyc) · The Daily WTF · 26 upvotes · 2 comments
- [10 Rare SQL Features Every Developer Should Know](https://daily.dev/posts/10-rare-sql-features-every-developer-should-know-fvu4qwczx) · Medium · 1 upvotes · 0 comments
- [Beautiful T-SQL Queries: Three Could Delete the Company](https://daily.dev/posts/beautiful-t-sql-queries-three-could-delete-the-company-ni51yxeeb) · SQL Authority · 36 upvotes · 7 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#microsoft-sql-server](https://daily.dev/tags/microsoft-sql-server), [#vector-search](https://daily.dev/tags/vector-search)

[View this post on daily.dev](https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"SQL Decomposition in a Nutshell","url":"https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi"},"datePublished":"2026-09-09T15:58:02.071Z","dateModified":"2026-09-13T19:10:52.571Z","description":"Application development principles like decomposition, encapsulation, and statelessness apply just as well to T-SQL as they do to object-oriented code. Using a...","image":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","thumbnailUrl":"https://media.daily.dev/image/upload/s--HRgLpUt6--/f_auto/v1722860399/public/Placeholder%2003","isAccessibleForFree":true,"articleSection":"DevBlogs","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"DevBlogs","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/8f68b453325f482ebeb73fb780092713","url":"https://daily.dev/sources/devblogs"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,microsoft-sql-server,vector-search","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"DevBlogs","item":"https://daily.dev/sources/devblogs"},{"@type":"ListItem","position":3,"name":"SQL Decomposition in a Nutshell"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/sql-decomposition-in-a-nutshell-g5hnrstpi#faq","mainEntity":[{"@type":"Question","name":"How can I break a complex hybrid search stored procedure in T-SQL into smaller, testable components?","acceptedAnswer":{"@type":"Answer","text":"Split the pipeline into independent stored procedures for full-text search, vector search, and fusion, each with a clear input/output contract. Use a user-defined table type such as a ProductId/Rank shape to pass results between stages, then compose them with a thin orchestrator procedure that calls each in sequence and passes data explicitly as parameters rather than relying on shared session state. daily.dev surfaces patterns like this for developers structuring maintainable T-SQL pipelines."}},{"@type":"Question","name":"How do you combine full-text search and vector search results in SQL Server using reciprocal rank fusion?","acceptedAnswer":{"@type":"Answer","text":"Convert each retriever's output to a simple 1..N rank rather than comparing raw scores directly, since FREETEXTTABLE ranking and vector distance are not comparable. Apply a reusable function computing 1.0/(60+Rank) to each result set, union the scored rows, then sum scores per ProductId with GROUP BY and order by the summed FusionScore to get the final ranking. teams building hybrid search in SQL Server can track fusion techniques like this via daily.dev."}}]}
```

