The Bit Bucket

Echoes from the field 5: Controlling stored procedure execution context (Part 1)

This is part 1 of a two-part series that shows you how to use the EXECUTE AS clause to change and control security context for stored procedures. Up next month will be digital signatures.

During a recent consulting engagement, I noticed that the client needed to control the security context that a stored procedure was running under but was using a convoluted method to do so. Changing the security context that stored procedures run under is a common requirement, letting users execute code via stored procedures that they aren’t allowed to execute directly.

2025-11-06

General: Prioritizing random adverts on Hugo-based Azure Static Websites

I posted a while back about being able to have random advertisements for our training courses in the sidebar for my blog. You’ll see one to the right of this post.

That has been working great, and every time I do a new build (each day), each page ends up with a random course advertisement.

Priorities

What I’ve now decided though, is that I didn’t want all the courses to show up with the same frequency. I wanted to assign a priority to each one, from 1 to 10.

2025-11-05

SSMS Tips and Tricks 4-11: Encryption status in query status bar

One of the bigger changes in recent versions of SSMS has been the inclusion of connection encryption details on the main connection page:

Previously, this was on another page of the logon dialog. Once you make the connection though, there previously was no indication of what type of encryption was used. Now that appears in the query status bar as a lock. When you hover over the lock, it shows you the type of encryption that had been selected.

2025-11-04

General: Are we beyond being able to believe the truth?

I was reading a Facebook post the other day, and it was talking about the sad tale of Keith Sapsford. Keith fell to his death from within the landing gear area of a DC-8 that was leaving Sydney, bound for Tokyo.

What was fascinating was that his fall was inadvertently captured by an amateur photographer named John Gilpin.

But why this fascinated me now, is that when I read all the comments about the post, the vast majority of the comments were saying that the photo was fake, that it was AI generated, and that this could not possibly have happened.

2025-11-03

Echoes from the field 4: Unique indexes vs unique constraints

Uniqueness can be implemented by primary keys, unique constraints and unique indexes. The use of primary keys is well understood but confusion exists about unique constraints and unique indexes.

This issue arose from a consulting engagement I was performing earlier in the month. During one of the architectural discussions I was having with the client, an interesting question was suddenly posed: When would you ever use a unique index?

After thinking about this for a moment, I suddenly realized that I almost never would use one and so I raised the topic on a technical discussion forum. An interesting discussion ensued and I’ve summarized the key thoughts in this article.

2025-11-02

General: Adding a rich RSS feed to a Hugo-based Azure Static Website

I posted a while back about moving to using Hugo-based Azure Static Websites for my blog and other simple sites.

One thing I’ve had a number of requests for over the years, is a richer RSS feed for my blog. In particular, while I have a coverImage tag in my front matter, the coverImage didn’t appear in the default RSS feed. I had a few requests about that one. So I set about trying to add a better RSS feed.

2025-11-01

SQL Interview: 90 Truncate table failing

This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.

Section: Administration Level: Medium

Question:

You are trying to truncate a table but the command is failing.

Can you give some examples of what can cause a truncate command on a table to fail?

Answer:

One common reason is that the table is referenced by a FOREIGN KEY constraint. (But you can truncate a table that has a foreign key that references itself).

2025-10-31

SSMS Tips and Tricks 3-18: Scrolling sensitivity

When I’m editing large script files in SSMS, I sometimes find that the scrolling speed of my mouse wheel is too fast or too slow.

If you don’t like the current speed, SSMS has an option to adjust that.

It’s in the Text Editor, Advanced, section. It allows you to control how many lines you get per scroll (for vertical scrolling) or how many characters (for horizontal scrolling):

2025-10-30

Echoes from the field 3: Views, stored procedures, and abstraction

You shouldn’t have to know how a view or stored procedure works or its internal code structure to use it. To that end, it’s time that stored procedures expose detailed contracts.

Many DBAs don’t allow users direct access to tables in SQL Server databases and instead give them access only via a series of views and stored procedures. One of the cited benefits of this approach—beyond providing a security boundary—is that the views and stored procedures provide a layer of abstraction over the underlying data.

2025-10-29

SSMS Tips and Tricks 3-17: Intellisense casing for function names

When I write T-SQL, my standard is to use upper-case names for built-in system functions. But not everyone likes that.

I’ve done a lot of work on systems where all these names are lower-case. I don’t have any great objection to that, but it’s painful if Intellisense keeps making them upper-case.

But there is a solution. In Text Editor, Transact-SQL, then Intellisense, there is an option for this:

2025-10-28