E
Erland Sommarskog
sommarskog.se · Personal blog · on HN since 2011
Erland Sommarskog, a SQL Server expert, publishes long technical articles on T-SQL, dynamic SQL, error handling, and query performance.
What HN saysCommenters call it a great, very thorough resource, pointing to the 100-plus page error handling series and the well-known query plan mysteries article.
15HN people shared it
7linked it in comments
8stories submitted
8story points
3 years agolast shared
2011people per year2026
Most-shared posts
- 1Slow in the Application, Fast in SSMS? Understanding Performance Mysteries8 people · 5 points · first shared 2013 · discussion on HN
- 2Homepage2 people · first shared 2017
- 3Using a Table of Numbers1 people · 1 points · first shared 2022 · 1 comments on HN
- 4Dynamic Search Conditions in T-SQL1 people · 1 points · first shared 2012 · discussion on HN
- 5The Curse and Blessings of Dynamic SQL1 people · 1 points · first shared 2023 · discussion on HN
- 6Part31 people · first shared 2018
- 7Part21 people · first shared 2018
- 8WhenThingsGoWrong%20(SQLSat%20706).zip1 people · first shared 2018
- 9Share data1 people · first shared 2011
- 10Part11 people · first shared 2018
What HN people wrote when they linked it
some_user54 · 2018-09-17
If you want to trully know how thing works I suggest great blog:
http://sommarskog.se/error_handling/Part1.html
http://sommarskog.se/error_handling/Part2.html
http://sommarskog.se/error_handling/Part3.html
More than 100 pages of technical knowledge.
And presentation: http://www.sommarskog.se/present/WhenThingsGoWrong%20(SQLSat%20706).zi…
dspillett · 2021-08-03
Another reason to write your own technical content, even if a similar question/answer does exist on SO, especially in examples where you experiment to put together examples that show/prove a point, is that it is practise for yourself.
I intend to get some of my own content out there (it may never happen, the intention has existed for quite some time!) and if I ever find time to do it some of the things I might include are expansions of things I've given as SO answers, expanding on details that might have been too much in the SO/SE context and potentially caused confusion or sliding off into tangents that would be too far off-topic from the starting point. I might not ever point people at this writing, the main point of it will be my own practise (of technical matters, and just the act or writing and organising information). If it comes to be something that feels useful then it might be the start of an online portfolio that I selectively send people to, or feed back into SO/SE (i.e. giving an answer with bits extracted from something I've already written with a “for some related tangents you might find this fuller article useful” link, as I already do for other people's articles like the very useful tomes of MS SQL knowledge at https://www.sommarskog.se/ that I've referenced on DBA.SE before now).
globalgoat · 2017-01-06
DougBTX · 2019-10-20
For SQL Server there’s a very nice article on making query plans more predictable here: http://www.sommarskog.se/query-plan-mysteries.html
hobs · 2019-01-31
Yeah, parameter sniffing is also a concern and a thing you have to manage on the SQL Server side - it's led to probably the most venerable article on the topic in that community - http://www.sommarskog.se/query-plan-mysteries.html
xtrumanx · 2014-10-31
I made an app that generated reports. The queries ran quickly when I tested it directly on the database but when I ran my app it would hang on a particular query. Sometimes.
I started making some small seemingly insignificant changes to my code and suddenly my app generated all the reports quickly. All was well until the next month when I had to generate the same reports and my app failed on the same query. I solved it by reverting the small insignificant change I made the previous month. WTF.
I looked into it and there's a wealth of information on the topic[0]. Apparently, how my code passed the query to the database differed to how I tested my query directly on the database which cause the database to compile the query differently and use different execution plans.
My most recent fix was to add another index which the database suggested. Let's hope it works next month.
[0] http://www.sommarskog.se/query-plan-mysteries.html
cameronh90 · 2011-08-01
I disagree with this article. SQL is an decent (though crusty) language when used specifically for the purposes of interacting with relational databases. The fact that most database vendors have hacked mutually incompatible proprietary extensions on-top of it for doing other tasks doesn't make it a good choice for them. Why would you use SQL over a language that has been specifically designed for code reuse, integration and interacting with multiple systems (rather than just the database)?
> Myth #1: Stored procedures can't be version controlled
Of course they can, but unlike normal code which runs/builds directly from the file-system, a sproc tends to be written directly on the database server (since you won't get all those fancy refactoring/debugging tools unless you do so). Copying it to the fs before committing your changes is a step that people often forget, or one that requires yet more tools.
> Myth #2: Managing the impact of changes in the database is hard
> Myth #3: Database tools lack modern IDE features
His examples of basic refactoring tools hardly compares to something like ReSharper.
> Myth #5: Code in the database can’t be properly encapsulated and reused, you need an object-oriented language for that
They can be encapsulated, but it's a pain. Even just getting data from one stored procedure to another can involve hackery like opening a connection to the database from inside the calling procedure. See this link: http://www.sommarskog.se/share_data.html -…