Sdu-Tools

SDU Tools: Last SQL Server Restart

SDU Tools: Last SQL Server Restart

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. A request that I had a while back was to have a function that returned the last time that SQL Server was restarted. So we added the LastSQLServerRestart function.

It takes no parameters.

I used to have a more complex way to work this out, but thanks to a great suggestion from our buddy Rob Wylie, it now just looks for the creation time of tempdb. That’s pretty good and simple to implement.

2025-02-17

SDU Tools: List Constraints with System Names in SQL Server

SDU Tools: List Constraints with System Names in SQL Server

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. I do a lot of reviewing of database designs and one of my least favourite things to see is the use of default system names for constraints. So we added a tool that can help to find when this has happened. It’s called ListConstraintsWithSystemNames.

The procedure takes three parameters.

2025-02-13

SDU Tools: Format Australian Phone Number

SDU Tools: Format Australian Phone Number

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. One request that we had some while back, was the ability to format phone numbers using Australian phone number format. To make that easy, we added the FormatAustralianPhoneNumber function.

The only parameter for this function is the phone number that needs to be formatted.

It starts by finding any digits. Then if it finds either 6, 7, 8, or (the standard) 10 digits, it formats the number appropriately.

2025-02-09

SDU Tools: Languages in SQL Server T-SQL

SDU Tools: Languages in SQL Server T-SQL

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. Applications often need to display a list of languages for users to choose from. To make that easy, we have now included a view called Languages.

The Languages view returns details of all the world’s languages, based on ISO 639-1. For each language, the view returns:

  • FamilyName
  • LanguageName
  • NativeLanguageName
  • ISO2CharacterCode
  • ISO3CharacterCode

The FamilyName indicates the group of languages that the language belongs to. The LanguageName is what we call it in English. The NativeLanguageName is what locals call the language. And then there are the 2 and 3 character codes from the ISO standard.

2025-02-08

SDU Tools: ExcelSerialToDateTime and DateTimeToExcelSerial

SDU Tools: ExcelSerialToDateTime and DateTimeToExcelSerial

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. Excel is fascinating in how it stores data. I have friends who joke that everything in Excel is a number or a string, and anything else you see is an illusion.

Date and time values in Excel are odd and use what most call a serial number when they’re stored. It’s common to need to import values from Excel into SQL Server and to export values to Excel.

2025-02-07

SDU Tools: Tools View

SDU Tools: Tools View

Our free SDU Tools for developers and DBAs, now includes a very large number of tools, with procedures, functions, and views. A while back, we added the ability to retrieve the version of the toolset programmatically, but an interesting request that we had, asked for the ability to query the toolset for the tools themselves. The Tools view now does that.

The view returns the following columns:

ToolName ToolTypeCode ToolType Category Description VideoURL

2025-02-03

SDU Tools: Calculate Age in Months

SDU Tools: Calculate Age in Months

Another request that I received a while back, for a new function in our free SDU Tools for developers and DBAs, was to be able to find someone’s age in months. The same would apply to anything where the distance between two dates needs to be measured in months. In response, we added a new function CalculateAgeInMonths.

It takes two parameters:

@StartingDate date - the date to calculate from (could be a birth date if it’s an age) @CalculationDate date - the date to calculate the age to

2025-02-02

SDU Tools v24 is now available for download

SDU Tools v24 is now available for download

Just a heads-up that v24 of SDU Tools went out to SDU Insiders last week. If you haven’t used SDU Tools, they are just a large library of functions implemented in T-SQL. You can use them as a full library or use them as examples of code in work you are trying to do.

Backwards Compatibility

We’ve also tried to keep all the code working for all versions of SQL Server that we see clients using. That means from SQL Server 2008 to SQL Server 2022. We also have an Azure SQL DB version.

2024-09-10

SDU Tools: List use of Deprecated Data Types in a SQL Server Database -> Updated

SDU Tools: List use of Deprecated Data Types in a SQL Server Database -> Updated

I’ve previously posted about the procedure ListUseOfDeprecatedDataTypes in our free SDU Tools for developers and DBAs. I mentioned that I’m often reviewing existing databases and one of the first things I go looking for is the way they’ve used data types, and that in particular, I’m keen to know if they’ve used any deprecated data types (i.e. ones that will/might be removed at some point).

The procedure was updated in version 21 to now include a ChangeScript column. (Thanks to Michael Miller for the suggestion).

2023-06-02

SDU Tools v23 is now available for download

SDU Tools v23 is now available for download

Just a heads-up that v23 of SDU Tools went out to SDU Insiders yesterday.

You can find details about SDU Tools here: https://sqldownunder.com/freestuff

In v23, we’ve added or enhanced the following:

  • ExcelSerialToDateTime - there’s so much corporate data stored in Excel, and if you need to import it to SQL Server, you quickly find that dates and times are a challenge. I have a friend who says that the only data types in Excel are numbers and strings, and that everything else is an illusion. I think that’s pretty accurate. This function takes one of the funky Excel decimal numbers (called a Serial) that represents a date and time, and converts it to a SQL Server datetime value.
  • DateTimeToExcelSerial - no prizes for guessing what this one does. It’s the opposite of the above.
  • We’ve done a lot of updates to internal data within the tools, like all up to date SQL Server build numbers, etc.
  • DateDimensionColumns now has StartOfWeek and EndOfWeek
  • DateDimensionPeriodColumns now has IsSameWeek, DayOffset, MonthOffset, and WeekOffset

You can see a short video on the new Excel conversion functions here: YouTube Video

2023-01-19