The Bit Bucket

Snowflake for SQL Server Users - A Christmas Present

I’ve had a lot of great feedback on my series of blog posts about Snowflake, and explaining the concepts for an existing SQL Server audience.

Just out for Christmas is a new free eBook for our SDU Insiders. I’m preparing a three part series on Snowflake for SQL Server users:

  • Part 1: Core Concepts (available now)
  • Part 2: SQL Language (coming soon)
  • Part 3: Administration (sometime after that :-))

You can get part one now! And did I mention free? (for SDU Insiders)

2019-12-27

SQL: Violation of SQL Server UNIQUE KEY constraint but entry doesn't already exist

One issue that comes up time and again in the forums is when an INSERT statement fails with a violation of a UNIQUE or PRIMARY KEY constraint but when the user checks the existing table, the value that’s being complained about isn’t already in the table.

The Symptom

For example, a table might have primary key values of 2, 12, and 14.

When an INSERT is performed, there is an error telling you that you can’t insert a duplicate key value of say 15.

2019-12-26

Happy Christmas 2019 to all my readers

Hi folks,

2019 has been another really big year. The number of readers of this blog has really increased in the last year and I’m pleased you’re here as one of them.  You make it all worthwhile.

Thanks to so many who reached out during the year, with wonderful insights and ideas.

Just wanted to wish you all the best for the holiday and Christmas season, from here down under.

2019-12-25

T-SQL 101: 49 Using REPLICATE to repeat strings in SQL Server

REPLICATE is an easy function to work with. It takes a string and a number of times you want it repeated. Here’s an example:

In this case, I’ve asked it to replicate (i.e. duplicate many times) an A character. I’ve asked for 5 of them. I put an X at each end so you could see the effect more clearly.

There are many things this can be used for, but for example, if I wanted to draw a line with 100 dashes, I could just ask for REPLICATE(’-’, 100).

2019-12-23

Snowflake for SQL Server Users - Part 20 - Encryption within Snowflake

As with most products today, Snowflake has substantial handling of encryption to protect client data.

All editions claim to provide “Always-on enterprise grade encryption in transit and at rest”.

In Transit

First, for connections, HTTPS and TLS 1.2 are used throughout the system.

If the customer is using external stages (holding locations in cloud-storage accounts), the data can be encrypted while stored in the stage, and then travel encrypted into Snowflake. To do that, you create an “encrypted stage” where you tell Snowflake the master encryption key (i.e. the client side key) when creating the stage:

2019-12-20

SDU Tools: Script User Defined Server Role Permissions in SQL Server

As part of our free SDU Tools for developers and DBAs, we have many scripting functions. SQL Server allows you to create your own server roles, and generally, you should do this instead of using the fixed server roles, as it lets you allocate just the required permissions. To allow scripting the permissions that have been assigned to the roles, we’ve added a tool called ScriptUserDefinedServerRolePermissions.

It’s a function and doesn’t require any parameters.

2019-12-18

Training: Give yourself a Christmas present - learn something new

It’s that time of year where people give each other presents. Why not give yourself a present and learn something new while you’ve got a chance?

Our latest course release is: SQL Server Integration Services for Developers and DBAs.

You’ll find it, and our other courses here now:

https://training.sqldownunder.com/

  • 4 Steps to Faster SQL Server Applications (Free)
  • Protecting SQL Server Data with Encryption
  • Writing T-SQL Queries for SQL Server (Low cost)
  • SQL Server Reporting Services for Developers and DBAs
  • SQL Server Spatial for Developers and DBAs
  • SQL Server Indexing for Developers
  • SQL Server Service Broker for Developers and DBAs
  • SQL Server Service Broker for Developers and DBAs
  • Working with SQL Server Replication

And many more coming soon.

2019-12-18

SQL Down Under Podcast Show 77 with guest Rob Sewell

I’m pleased to announce the release of another SQL Down Under podcast.

Show 77 features Cloud and Datacenter Management MVP Rob Sewell discussing the popular Powershell dbatools.

In the show, Rob discusses the background of the tools, how they’ve evolved, how to install them, and how you can get involved in contributing to them and other open source projects.

Rob and Chrissy Lemaire (the initial author of the tools) have written a new book on the tools and you can find it here:

2019-12-17

T-SQL 101: 48 Replacing characters in strings in SQL Server using REPLACE and STUFF

I often need to replace characters in one string with other characters. There are three basic functions in T-SQL for doing that. The most common two functions for this are REPLACE and STUFF.

REPLACE is a simple function. You tell it which string to work on, the substring to find, and which string to replace it with. You can see it here:

I asked it to replace all occurrences of DEF with HELLO. Note that the replacement doesn’t need to be the same length as what it’s replacing. A very common use of REPLACE is to remove characters by making the replacement string just a blank string.

2019-12-16

Snowflake for SQL Server Users - Part 19 - Fail-Safe

In the previous post in this series, I talked about how historical data in Snowflake can be accessed by a concept called Time Travel. But Time Travel isn’t the only way to get to historical data.

In Snowflake, Fail-safe is a system that provides protection against system failures and other nasty events like hardware failures or serious security breaches.

Immediately after the Time Travel retention period ends, a Fail-safe period begins.  It lasts for a non-configurable period of seven days.

2019-12-13