Sql-Server

T-SQL 101: 32 Repeating T-SQL batches with GO n

In my last T-SQL 101 post, I mentioned that GO was just a word that’s used to separate batches. In fact, it’s not a SQL word at all. If you actually send the word GO to the server, it wouldn’t know what you’re talking about.

I mentioned that the word is only understood by the program that you type the script into. SSMS also allows us to make use of another additional trick in relation to GO.

2019-08-26

Snowflake for SQL Server users - Part 3 - Core Architecture

The first thing to understand about Snowflake is that it has a very layered approach. And the layers are quite independent, including how they scale.

Cloud Provider Services

The lowest level isn’t part of Snowflake; it’s the services that are provided by the underlying cloud provider. As a cloud native application, Snowflake is designed to use services from the cloud provider that they are deployed to, rather than providing all the services themselves. At present, that means AWS or Microsoft Azure. Deployment on Google’s cloud platform is in preview at this time.

2019-08-22

SDU Tools: Create SQL Server Login with SID from a database

In SQL Server, both logins (access to the server) and users (access to a database) have a name and a security ID (SID). This leads to problem situations where names might match but SIDs don’t match.

Common Problem

I’ve lost count of the number of times I’ve seen a user restore a database from another server, and then realize that the SQL Server login they need wasn’t present. Then, they create a new login and end up in a lousy situation, because the new login’s SID doesn’t match the SID of the user in the database.  I call this a mismatched SID issue.

2019-08-21

T-SQL 101: 31 Understanding batches, scripts, and GO

The image below shows a T-SQL script.

It’s an example of contents of a file that you could have on your disk so the entire thing could be called MyProgram.sql. Inside this script file, we’ve got a few different types of things happening here.

The word script applies to all of the contents of the file.

You can see the word GO there a number of times. It’s a special word that’s not actually a T-SQL keyword. It’s a batch separator. It only has meaning to the tool you’re using to execute queries, like SQL Server Management Studio or Azure Data Studio.

2019-08-19

SDU Tools: Calculate string length in SQL Server T-SQL

If you ask SQL Server developers how to calculate the length of a string in T-SQL, most would tell you immediately that you need to use the LEN() function. What most don’t realize though, is that it doesn’t actually work properly.

The T-SQL LEN() function ignores any trailing spaces in a string.

That’s not how a string length function should work, or how it works in most languages. So, in our free SDU Tools for developers and DBAs, we added a simple tool that works properly. It’s called StringLength.

2019-08-15

Snowflake for SQL Server users - Part 2 - Cloud First Design

In recent years, I’ve done a lot of work in software houses (Microsoft calls them ISVs or Independent Software Vendors). Many of these software houses have worked out that they won’t be able to just keep selling their on-premises applications because their customers are asking for cloud-based solutions.

And more importantly, the customers want the software houses to manage the applications rather than themselves. So, many of the software houses start trying to turn their on-premises applications into Software as a Service (SaaS) applications.

2019-08-15

T-SQL 101: 30 Changing databases with the USE statement in T-SQL

Take a look at the following query:

I’ve asked for a list of the databases from the sys.databases view. But rather than executing it against whichever database I was already connected to, I’ve said USE master; to change to the master database.

The command will be sent to the master database instead of any other database that I might have been connected to. At that point, master becomes my “current database”.

2019-08-12

Snowflake for SQL Server users - Part 1 - Why Snowflake?

A few months back, I started noticing that many of our clients had started to mention Snowflake.

In recent years, I’ve been in lots of planning and architectural meetings where there was already a presumption that AWS was being used rather than Azure. I put that down to a great selling job by the AWS people who got corporate IT folk locked into large enterprise agreements early. And so no matter what the technical question is, the answer will be something that runs on AWS.

2019-08-09

SQL: Maintaining Online Website Data during Full Data Refreshes

I’ve got a number of clients in the superannuation (aka retirement fund) industry. At many of these sites, there is a need to be able to do this:

  • Using a web site, members must be able to see their own data pretty much 24x7
  • Some latency is ok i.e. it might be ok for a member to see data up to yesterday, or up a point in time a few hours ago
  • Refreshing the website data is not incremental, truncating the tables and reloading them is required

The challenge is: what happens if a member looks at the data during the time it’s being refreshed?

2019-08-08

SDU Tools: Calculate Time Period Dimension Columns in SQL Server T-SQL

In my last SDU Tools post, I described a tool for calculating date dimension columns. While dates are often enough, in many data warehouses, you also need to allocate time periods across each day as well. To make that very easy, in our free SDU Tools for developers and DBAs, we added a tool called TimePeriodDimensionColumns.

This tool is a table-valued function that takes a time (actual time of the day), and the length of each time period, in minutes. In the example in the main image above, I’ve asked for 8:34PM and I’ve said that each period is 15 minutes long.

2019-08-07