Erland Sommarskog's home page
I'm an independent consultant who provides expert consulting in the SQL
Server area. I was awarded Most Valuable
Professional on SQL Server by
Microsoft in April 2001. This page gathers articles and utilities that I have
written about and for SQL Server. Details on my consulting business are
available here in Swedish and here in English. The English page includes some
information about me as a person. I also have a photo gallery.
To see what has changed on this site recently, please see my web log.
Texts on SQL
This is a small collection of texts about some features in SQL Server that
people frequently ask about in the newsgroups about MS SQL Server. Rather
than being a FAQ with many questions with short answers, these are in-depth
articles on some of my favourite topics
- The curse and blessings of dynamic SQL.
How you use dynamic SQL, when you should – and when you should not. German
translation of an old version available. Latest revision:
- Dynamic Search Conditions. How to
write a stored procedure that permits users to select among many search
conditions, using both dynamic and static SQL. Latest revision: 2014-12-27.
- Giving Permissions through Stored Procedures.
SQL 2005 adds two new methods – signing with certificates and
impersonation with EXECUTE AS – that can manage cases where the
classic method of ownership chaining fails. I explain the two new methods, as
well as the old one, and warn you about the pitfalls. Latest
- Slow in the Application, Fast in
SSMS? Ever experienced the situation that your query runs slow in your
application, but when you try it in SQL Server Management Studio, the response
is immediate? This article explains why this may happen, what parameter
sniffing is and suggests methods to analyse and address your performance
problem. Latest revision:
2013-08-30. Russian translation available.
- Error and Transaction Handling in SQL Server. A series of three articles and three appendixes that discuss the bewildering topic of what may happen when an error occurs in SQL Server and how you should implement your error handling. The first part is a short jumpstart for everyone, while Parts Two and Three are in-depth articles. The appendixes cover special topics: linked servers, the CLR and Service Broker. There are also two old articles for SQL 2000. Latest revision: 2015-05-03.
- How to share data between stored procedures.
Different ways of passing sets of data between stored procedures. Latest revision: 2013-11-02.
- Arrays and Lists in SQL Server.
Several methods on how to pass an array of values from a client to SQL
Server, and performance data about the methods. There are three articles: one
for SQL 2008 which is devoted entirely
to table-valued parameters, one
for SQL 2005 and later (for
situations when you cannot use TVPs), and one for SQL 2000 and earlier. Latest
revisions: 2012-07-01 (SQL 2008) and 2012-11-02 (SQL 2005).
- Build Your Own Index. This is a
teaser for.. Well, follow the link and read on!
- Connecting to MS SQL Server from Unix.
A brief summary of what's available. Since I don't work with Unix myself, it's not
extremely well-informed, but people have kept asking me about this.
Latest revision: 2015-05-26.
My SQL Server Wishlist
I've compiled a list of Connect items related to development that I wish to see implemented in SQL Server, the sooner the better. Read it and vote for the suggestions you like! Latest revision: 2013-05-18.
Utilities and Code
All of this is code in the public domain.
- AbaPerls. A collection of tools for developing and deploying stored procedures,
tables and other SQL Server objects. You get a preprocessor, the ability to load stored procedures and get full object
checking directly. You will be able to build to update scripts from Team Foundation Server or SourceSafe and a lot more. AbaPerls is a tool that I
use in my daily work, and it's very much a living tool. Current label is 1.0.0294, released June 2013.
- beta_lockinfo. This is a stored procedure for lock-monitoring, giving
you a good snapshot so you can see who is blocking whom and what their current command is. Latest version: Version 19, 2015-02-01.
- Win32::SqlServer. Access SQL Server from Perl through OLE DB. Current version is 2.009, released
in May 2015.
- sp_sqltrace. A stored
procedure that takes an SQL batch as a parameter, sets up a trace, runs the batch, and then summarises the trace.
On SQL 2008 and later, you also get wait-stats information per statement. Optionally, you can get the execution plans for the statements. Rather than tracing your own process, you can snoop another spid. It is also possible to reanalyse a previously collected trace. A very useful tool for performance tuning developed by Lee Tudor that I am proud to host on my site. Latest version: Version 6, 2015-03-15.
You can reach me on email@example.com.