Composable logic

Composable logic is what some developers use to make a single T-SQL statement do more than one thing, which allows us to reuse the same code for multiple tasks. When writing procedural code, reusability is desired because it makes the code more concise and maintainable. It allows developers to create libraries of modules that can be reused in other areas of the application, or even in other applications altogether. In T-SQL however, there can be a hefty performance penalty for writing generic reusable code.

For SQL Server to execute a query in the most efficient way, it needs to estimate the cost of the query and choose operators that will return the results in the cheapest way possible. This is all done at compile time

Get Learn T-SQL Querying now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.