Categories
SQL

Setting Default Values

Defaulting values is a typical part of data ingestion and processing within SQL. Handling NULL values can cause issues in a number of ways so there are time when we want to get these out of our data. Recently I had a question about setting default values for a field which was being processed as […]

Categories
SQL

Using Regular Expressions in SQL Server

After being around SQL Server for the last 15 years I was surprised recently to see an example of Regular Expression (RegEx) syntax being used within a SQL query and knew it was something I wanted to try out for myself. What are Regular Expressions? If you haven’t head of them before, Regular Expressions are […]

Categories
SQL

Using Schemas in SQL Server

Schemas within SQL server allow for logical separation of data within a single database. A schema is an extra layer which can allow objects in the database – including tables, views, procedures, etc. – to be separated. They could be used simply to group objects together in a more user-friendly way or they can be […]

Categories
SQL

Indexing Computed Columns

In the previous introduction post we covered how to add a computed column to a table and that by default this becomes part of the table metadata when its created. Here we’re going to look at benefits we can get with the performance of these columns when applying an index to them. We’ll use the […]

Categories
SQL

Altering Computed Columns

In a previous post we covered some of the fundamentals about computed columns and we saw the benefits which they can bring for us. Once we’ve implemented them, one of the challenges we may have is if we need to make adjustments to their expression or the fields they reference. Lets start off with a […]

Categories
SQL

Introduction to Computed Columns

Using a computed column in a table allows you to have a calculation pre-baked into your schema. They also allow you to choose if you’d like that calculated value to be physically stored within the table (persisted) or to be calculated each time you query the table. To demonstrate this we’ll use a small sales […]

Categories
SQL

Deleting Data from a Heap

When it comes to removing data from a heap its pretty similar to removing it from a regular table: That’s all folks! Wait, or would you like your data pages back too? Yea, it might not be quite that easy… You see, when you remove a small number of records from a heap you’ll find […]

Categories
SQL

An Unfortunate Tale of Clustering a Heap

If you’ve ran sp_BlitzIndex before you might have come across some warnings about self-loathing heaps and maybe you’re looking to put a clustering key on them. Generally that’s a good idea to consider but it can cause issues if the data needed to be in that specific order. In this instance it turned out there […]

Categories
SQL

Removing Duplicate Records from a Heap

Dealing with duplicate records can be a headache when you’re expecting them to be unique and at some point the application or report users start to question why they’re seeing the same customer or product appearing twice. Once you’ve tracked them down you typically want to get rid of them and sometimes you’ll find an […]

Categories
SQL T-SQL Tuesday

T-SQL Tuesday #143 – Short Code Examples

The ask this month is to share go-to short code snippets with the community. I think its right to start by showing appreciation for some of the widely adopted tooling in the community such as sp_WhoIsActive, the First Responder Kit, Ola’s Maintenance Solution and DbaTools. Without these available we wouldn’t have half the snippets and […]