The Bit Bucket

SQL: The T-SQL SIGN function and what's in a return type?

When you’ve worked with a product like SQL Server for a long time, and more importantly, are one of the odd people who’ve read a great amount of the documentation simply for interest, it feels really strange to come across a basic function that you’d never noticed before. That’s how I felt when someone mentioned the T-SQL SIGN function.

I thought, “the what function??”.

Now it works pretty much as you’d expect. It returns:

2018-08-13

Book Review: Don't Sweat the Small Stuff - Richard Carlson

I’ve been going through a number of fairly famous books or ones that have spawned their own industry. One of those was Don’t Sweat the Small Stuff and it’s all small stuff: Simple Ways to Keep the Little Things From Taking Over Your Life by Richard Carlson.

This one intrigued me as there are now so many follow up versions. There’s a “for teens”, “for men”, “at work”, etc. etc. etc. along with ancillary items like workbooks. So I presumed there must have been something to it.

2018-08-10

New online on-demand SQL Server courses from SQL Down Under

Hi Folks,

We have a whole series of online and on-demand courses coming. The first two of these are available right now.

The good news? The first one is free and the second one has a big introductory discount.

The first course 4 Steps to Faster SQL Server Applications is a short course for developers, new DBAs, and testers, etc. who don’t know anything much about tuning SQL Server applications. It focuses on finding and fixing the most problematic queries, either in terms of index tuning, or removing repetitive queries, all using free tools.

2018-08-10

Shortcut: Adding additional parameters to connections in SSMS

When I am writing my own code using a .NET (or other) language, I have a great deal of control of how the connection string that my application uses to connect to SQL Server is configured.

In particular, I might need to add another parameter or two.

As a simple example, you might have a multi-subnet Availability Group, spread across a production site and a disaster recovery site. It’s common to then have an Availability Group Listener in both subnets.

2018-08-09

SDU Tools: ExecuteOrPrint - Printing large strings in T-SQL

The PRINT statement in SQL Server’s T-SQL language is useful but one of the biggest restrictions with it is the size of the strings that it can print. Where this becomes a big issue is if you are needing to create dynamic SQL statements (which you obviously need to be careful of in the first place) or scripting database objects, and the statements need to be either executed or printed.

2018-08-08

SQL: Use elevated procedure permissions instead of elevated user permissions

Choosing the right database permission can be hard. I’ve lost count of the number of times I’ve heard a discussion like this:

I need to let Mary restore truncate one of the tables but I don’t want to give her permission to do it, in case she stuffs it up.

or

I need to let Paul restore this database but I don’t want him to be able to restore other databases, and I’m worried if I give him the permission, he might accidentally do something bad and I’ll be blamed for it.

2018-08-06

Upcoming: User Group Tour in New Zealand soon

Hi Folks, we’re looking forward to doing a number of presentations across New Zealand starting around the end of this month.

Aug 27th (Mon): SQL Server User Group - Wellington (Things I wish Developers knew about SQL Server) Details here

Aug 28th (Tue): Data Management and Analytics Meetup - Wellington (A Comprehensive Look at What’s New in SQL Server 2017 - and ongoing product directions) Details here

Aug 31st (Fri): Pre-conference Day  for SQL Saturday - Auckland (Developing SQL Server Applications that Perform) Register here

2018-08-04

Book Review: A Higher Loyalty - James Comey

I don’t tend to read all that many books on US politics but I had heard interesting things about A Higher Loyalty - Truth, Lies, and Leadership by James Comey.

I was especially interested to hear this one on Audible, given the author was also the narrator. I really wanted to hear him explain his view on the situation.

Generally, I’d avoid a book like this because I was assuming it would just be a self-apologetic or self-aggrandizing account of recent events. What I found though was very, very different.

2018-08-03

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