The Bit Bucket

Shortcut: Using "surrounds with" snippets in SQL Server Management Studio

In previous posts, I’ve been talking about how to use snippets in SQL Server Management Studio (SSMS) and how to create your own. There are several types of snippets and one of the special types of snippets that I want to mention are the “surround with” snippets.

If you look at the following block of code:

Imagine that you want to execute the four highlighted lines only when a condition is true. If I hit Ctrl-K and Ctrl-S while they are highlighted, I’m prompted with this:

2018-08-02

SDU Tools: ExecuteJobAndWaitForCompletion

You can execute SQL Server Agent jobs from within T-SQL code. The procedure sp_start_job can do that.

That’s all well and good but notice that it doesn’t say “execute job”; it just says “start job”. The command starts the execution of a job but has no interest in when it completes.

Sometimes, you need to be able to start a job and wait for it to complete before taking a following action.

2018-08-01

Upcoming: Database on a Diet in Auckland (Taming a large database)

Just a reminder that as well as the pre-conference day and the keynote, I’ll be presenting my Database on a Diet session at SQL Saturday in Auckland. I regularly work with some pretty sizable databases at tier-one financial (and other) organisations and they all struggle with the size of their databases. It’s easy for the size of a large database to get out of control.

In the example in this session, I’ll  describe the techniques I’ve used to reduce an operating 3.6TB database to just over 500GB, while increasing its performance. The session will include a deep dive into compression and other related techniques within SQL Server.

2018-07-31

SQL: What is sp_reset_connection and should I care about it?

Anyone who’s ever traced activity against a SQL Server will have no doubt seen a large number of commands where the procedure sp_reset_connection has been executed. Yet, this command won’t appear anywhere in the source code of the applications that are running.

As an example of why this occurs, one of the most common data access technologies that is used to connect applications to SQL Server is ADO.NET. It has a SqlConnection object that represents a connection that can be opened to a SQL Server instance. In the design of the SqlConnection class, the architects of it were grappling with two big issues:

2018-07-30

Book Review: Hit Refresh - Satya Nadella

When I first heard that Satya Nadella had a book out, I was somewhat surprised as at the time, he had just taken over running Microsoft. Usually you don’t see books from CEOs until they’ve been in the role for quite a while and have become philosophical about things.

But given the impact I could see he would have, I was fascinated to read his book Hit Refresh.

It was actually quite a bit more than I expected. I really enjoyed the tales of his life and how it led up to his current role.

2018-07-27

Shortcut: Using bookmarks in SQL Server Management Studio

In a previous post, I was discussing how outlining can be helpful with navigating around within a large T-SQL script file.

If you were trying to do that within a Microsoft Word document, the most common thing to use is bookmarks, and SQL Server Management Studio (SSMS) has them as well.

Bookmarks are simply placeholders within a script. (They can also apply to other types of document within SSMS). Where I find them very useful is when I’m working in two or three places within a long script at the same time. Perhaps I’m working on a function, and also on the code that calls the function. By using bookmarks, I’m not flipping endlessly around the script file, and can jump directly from placeholder to placeholder.

2018-07-26

SDU Tools: DropTemporaryTableIfExists

I regularly find myself writing repetitive code in T-SQL. Some things are best done by just creating code snippets but we’ve also added several others to our free SDU Tools for developers and DBAs.

One straightforward one is DropTemporaryTableIfExists.

This just wraps all that’s needed to remove a temporary table if it exists. The nice thing with this procedure is that you can call it before creating a temporary table, and call it again after you finish using the temporary table, as shown in the main image above.

2018-07-25

Upcoming: Precon for SQL Saturday in Auckland

At the end of the month, I’ll be delivering a pre-conference session in Auckland on Friday 31st of next month (August). Would love to see you there. Details are as follows:

Developing SQL Server Applications that Perform

So many SQL Server applications today are so slow, even simple ones, yet the product is capable of amazing performance, even in tier-1 organizations. Greg spends his life working with SQL Server developers (from the smallest startup software houses to many large tier-1 organizations), working with them to get their applications flying.

2018-07-24

SQL: What's in a (default) name?

I often see people creating databases in SQL Server and not specifying the name of defaults they are applying to columns. They define a column like this:

And there are general reasons why this makes sense. For example, a column can only have one default, so what does the name matter anyway?

There are two reasons:

Dropping columns

In SQL Server, you’ll find that if you go to drop either of those columns, you’ll see something like this:

2018-07-23

Book Review: Blockchain - by Samuel Rees

Another book I’ve read recently while sitting on a few planes is Blockchain - by Samuel Rees.

I’ve seen some big claims in the titles of books but this one had me intrigued:

The Ultimate Beginner Through Advanced Guide on Everything You Need to Know About Investing in Blockchain, Cryptocurrencies, Bitcoin, Ethereum and the Future of Finance

That’s quite a claim. I was really hoping this book would provide a great amount of detail given it’s ‘beginner through advanced’ guide claim.

2018-07-20