A simple Calendar Table example

A tool I find I often tell people that really should have already implemented in their environment is a Calendar table, however, something I don’t actually have to show them is my own example. As such I felt it time to provide one, so that next time someone asks me "what should it look like", I can demonstrate it. The Calendar Table I have in my Utility database is actually all most entirely made up of computed columns; the only column that isn’t is the Calendar Date. With the exception of the name columns as well, all the columns are…

Continue reading

Azure Data Studio is being retired and I am concerned…

Some of you may, or may not know, Microsoft announced the deprecation of the Azure Data Studio (ADS) on 06 February, with support ending next year on 28 February. For those of using ADS Microsoft recommends migrating to VSCode and using the mssql extension. Honestly, I’m really concerned about this. I tried the mssql extension for VSCode (mssql going forwards) some time ago, and compared to ADS it was incredibly feature lacking. A lot of stuff I want to do as a DBA was completely missing, so I went straight back to ADS and didn’t look back. I like ADS,…

Continue reading

An introduction to parametrised queries with DbaTools

Many of us are likely aware of PowerShell, even if we don’t use it too frequently, and I suspect that if you’re reading this post you’re also familar with things like sqlcmd. Hopefully, you have also heard of DbaTools, a module for PowerShell (and if you haven’t, hopefully that’s why you’re here). Today, I wanted to discuss running parametrised queries (including table type parameters) from PowerShell, which is notorious hard/impossible with sqlcmd (or invoke-SqlCmd), using the DbaTools module. Running a basic query Firstly, let’s get the real basics down, and look at connecting to the SQL Server, and running a…

Continue reading

Stop using ROLLBACK in triggers; THROW an error

A problem I’ve seen raised on numerous occasions is users that are getting a non-descript error when they are doing some kind of DML/DDL operation, and they don’t know why they are getting the error, and what is causing it. That error is: Msg 3609, Level 16, State 2, Line 1 The transaction ended in the trigger. The batch has been aborted. So, for the "unsuspecting" user that’s performing an INSERT or maybe an ALTER statement, all they know is that the statement failed in a trigger. There are no details what what trigger caused the error, and no details…

Continue reading

Getting the line sys.sp_executesql was executed on during an error

This is a problem I encountered recently on a question on Stack Overflow but found it interesting enough that I wanted to also share it here. When you are using dynamic SQL, you may have noticed that when an error occurs the line number provided in the error is that of the query in the dynamic batch, not the outer query. Take for example the following example: DECLARE @SQL nvarchar(MAX), @CRLF nchar(2) = NCHAR(13) + NCHAR(10); SET @SQL = N'DECLARE @name sysname;' + @CRLF + N'SELECT @name = name' + @CRLF + N'FROM sys.tables' + @CRLF + N'WHERE object_id =…

Continue reading