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. If you have attended any of my presentations and want to look at slides and scripts, look here.
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: 2016-10-29.
- Giving Permissions through Stored Procedures. How you can package permission inside a stored procedures, so that users can performed privileged actions in a way you have control over. I start off with describing the classic method of ownership chaining before I embark on the two methods you can employ when ownership chaining does not cut it – certificate signing and
impersonation with EXECUTE AS. 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:
2016-18-12. 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: 2016-12-18.
- How to share data between stored procedures.
Different ways of passing sets of data between stored procedures. Latest revision: 2013-11-02.
- Using Table-Valued Parameters in SQL Server and .NET. A primer on how to pass data through table-valued parameters from a .NET program to SQL Server with practical examples of how load a comma-separated lists and a file with master-detail data. Latest
- Arrays and Lists in SQL Server. A series of articles of who to handle comma-separated lists and related in SQL Server. The first is a short introduction which is all you need to read for the simple case. It links further to the the second which covers a lot of methods from several aspects including performance. There is also an old article for SQL 2000 and earlier. Latest
- Using the Bulk-Load Tools in SQL Server. An article that covers BCP, BULK INSERT and OPENROWSET (BULK) from a functional point of view. You will learn about format files and how you can use them to tackle various file formats, but you will also learn what formats they are not able to handle. First published: 2016-12-18.
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: 2016-10-09.
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 21, 2016-06-03.
- Win32::SqlServer. Access SQL Server from Perl through OLE DB. Current version is 2.010b, released
in November 2016.
- 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 8, 2016-03-29.
You can reach me on email@example.com.