The Bit Bucket

Opinion: Security is hard - the Sad Tale of the Windows Calculator

Opinion: Security is hard - the Sad Tale of the Windows Calculator

Ever since I’ve done development work on Windows, I’ve seen two things happening:

  • People arguing that development should never be performed in an admin account
  • People using admin accounts for development because otherwise they can’t get anything done

This is a long-term nasty problem, but I thought I’d share today an anecdote I was told by a Microsoft product group member about how easy it is to get security wrong during development, if you always develop as an admin.

2019-02-22

Shortcut: Configure SSMS auto-recover time, and recover unsaved queries

Shortcut: Configure SSMS auto-recover time, and recover unsaved queries

Every now and again, I come back to my laptop and find that it has rebooted for some reason, while I wasn’t expecting it. A prime cause of that is Windows Updates. I really, really wish that wasn’t so, but someone at Microsoft has decided that I must apply these updates. I have very little control over the time when that occurs. For example, if I’m on the road delivering presentations, there’s no “wait till I get home” option for Windows Updates.

2019-02-21

SDU Tools: Time Period Dimension Columns in T-SQL

SDU Tools: Time Period Dimension Columns in T-SQL

In a previous SDU Tools post, I described how to calculate the columns required for a date dimension. Another related tool that we have in our free SDU Tools for developers and DBAs, is a function that creates the columns needed for a time period dimension. It’s called TimePeriodDimensionColumns.

You supply the starting time, and the number of minutes per time period,  and it supplies the output columns.

You can see it in action in the main image above, and in this video:

2019-02-20

SQL: The outcome of how DateDiffNoWeekends should work

SQL: The outcome of how DateDiffNoWeekends should work

In a recent post, I discussed questions that had come up about how we should calculate the number of days between two given dates, but excluding the weekends i.e. people just wanted the number of weekdays.

This relates to one of our SDU Tools called DateDiffNoWeekends. Some customers using it felt that it didn’t calculate the days in the way they thought it should. And on reflection, I agreed.

Much of the discussion centred around how we should treat start and end dates, depending upon whether they were on the weekends or not.

2019-02-19

T-SQL 101: 5 Logging on to SQL Server

T-SQL 101: 5 Logging on to SQL Server

Before, you can access anything on SQL Server, apart from knowing what to call the server, the server itself needs to know who you are. This process is called authentication.

In SQL Server, a login is person that the server has identified.

Now access to the server by a login doesn’t mean that you can access anything much on the server, it’s just the first step where you get the server to trust who you are.

2019-02-18

SQL: Calculating Day of the Week Reliably in T-SQL

SQL: Calculating Day of the Week Reliably in T-SQL

Some T-SQL functions like DATEPART work differently based upon your session settings. If you want to write reliable code, you should always check for these issues, and try to write code that’s impervious to these settings.

Let’s take finding the day of the week as an example. It might seem that to find out if a day is a Sunday, you could just do this:

DECLARE @DayToCheck date = ‘20190224’;

2019-02-15

Shortcut: Clear server list in SSMS connection dialog

Shortcut: Clear server list in SSMS connection dialog

SQL Server Management Studio (SSMS) keeps a list of the server names that you have connected to, and prompts you with those when you drop-down the list while making a connection:

Eventually, that list can either become messy, it can include servers that don’t exist anymore, and so on. You might want to clear up the list.

To do this in early versions of SSMS, you needed to locate the SqlStudio.bin file from the Documents and Settings area in your user profile.

2019-02-14

SDU Tools: Calculate Date Dimension Columns in T-SQL

SDU Tools: Calculate Date Dimension Columns in T-SQL

Calculating the columns required for a date dimension using T-SQL is a pretty common request from SQL Server developers. So we decided to make it really easy to do. In our free SDU Tools for developers and DBAs, there is a table-valued function called DateDimensionColumns, for just this purpose.

You supply a date, and the month that your financial year starts in, and it supplies the output columns.

You can also easily combine it with our DatesBetween function to get dimension columns for a range of dates:

2019-02-13

Question: How should DateDiffNoWeekends work?

Question: How should DateDiffNoWeekends work?

One of the tools we have in our free SDU Tools for Developers and DBAs is a version of DATEDIFF that excludes weekends. It’s DateDiffNoWeekends.

This has been a very popular function.

One of the customers who is using these tools found that it was returning different results to what he expected. And it got me re-thinking how it should work.

Let’s start by assuming that weekends are Saturday and Sunday. That’s what most people seem to assume.

2019-02-12

T-SQL 101: 4 What are Server Instances in SQL Server?

T-SQL 101: 4 What are Server Instances in SQL Server?

Before you can start to execute queries against SQL Server, you need to connect to the server. The first concept that you need to understand is what a server instance is.

You need to know is what name you should use to refer to the server. As an example, if I have a computer called SDUPROD and it has a copy of SQL server installed on it, we could often just connect to the name SDUPROD. If we do that, then what we’re doing is connecting that what’s called the default instance of SQL Server.

2019-02-11