SQL

SQL snippets and guidance for database development. Covers key topics like choosing between single and multiple LINQ to SQL data contexts for your data layer architecture, and simulating Oracle-style rownum functionality in MySQL queries.

When you’re starting with LINQ to SQL, one of the first architectural decisions is whether to use a single DataContext or multiple DataContexts. I explain both approaches: the implications for connection management, transaction handling, performance, and maintainability. The right choice depends on your application’s complexity, data access patterns, and scalability requirements.

Rownum Simulation with MySQL

MySQL doesn’t have a built-in ROWNUM function like Oracle, but you can simulate row numbering using user variables. I share the exact SQL technique for adding sequential row numbers to your MySQL query results, including handling ordering, partitioning, and the common pitfalls that produce unexpected numbering. A practical solution for a frequently encountered database requirement.