|
|
|
|
|
by gregw2
1277 days ago
|
|
SQL doesn’t give you tools to break up code?? Err, I don’t agree there. I can think of four options just off the top of my head. Simplest is to use WITH clauses (common table expressions/CTEs). They can help readability a lot and add a degree of composability within a query. Second, you can split one query into several, each of which creates a temporary (or intermediate physical) table. Third, you can define intermediate meaningful bits of logic as views to encapsulate/hide the logic from parents. For performance you materialize them. Fourth, you can create stored procedures which return a result set and like any procedural or functional language chain or nest them. These techniques are available in most databases. More mature databases support forms of recursion for CTEs or stored procedures or dynamic SQL. As with most programming, proper decomposition and naming helps a fair bit. |
|