Finding Month Ends in T-SQL

Months are funny. Unlike other parts of a date, they vary in length: The last second of a minute is always 59. The last minute of a hour is always 59. The last hour of a day is always 23. But the last day of a month? Well that depends on what month it is. And the year matters too because a leap year means February gets an extra day. This used to be somewhat tricky to calculate, but then for SQL Server 2012 Microsoft added the EOMONTH() function (End Of MONTH) to T-SQL to help with this. EOMONTH() takes…
Read More

Mirroring? Make Sure Editions Match!

SQL Server Mirroring has had a rough time the past few years. It was deprecated in SQL Server 2016, and now it's more or less being replaced by Basic Availability Groups, (which I love to refer to as "BAGS"). Database Mirroring hasn't gone the way of the Dodo yet though. Perhaps it won't be quite so popular in new deployments anymore, but there's plenty of existing ones out there. For this reason I don't expect Microsoft to remove the feature for at least a few more years. A few weeks ago I had a reminder of one of the finer…
Read More

SQL Server 2016: What’s Going Away

  SQL Server 2016 is upon us, with all the much-anticipated hoopla and sexy new features people have been lusting over in the CTPs for months. It's always great to see the hype around a new release. But in the circle of (an application's) life, the arrival of new things often means others are going away for good. Let's pause for a moment and reflect upon the two features that, as of SQL Server 2016, are no longer with us: 32-bit SQL Server. SQL Server 2016 is 64-bit only. If for whatever reason you're running on a 32-bit architecture, sadly you're now…
Read More

Dropping Multiple Databases At Once

I'm already at peace with the fact that I'll never know all of SQL Server's secrets, but that doesn't stop me from being surprised every time I figure out something new. In this case, it's another "secret" hiding in plain sight (Books Online). It turns out that the DROP DATABASE statement doesn't just have to drop one database. BOL shows that multiple databases can be specified when separated with commas. Let's see it in action. First, create 4 databases: CREATE DATABASE DB1; CREATE DATABASE DB2; CREATE DATABASE DB3; CREATE DATABASE DB5; Now drop them: DROP DATABASE DB1, DB2, DB3, DB5;…
Read More