Problems displaying this newsletter? View online.
Database Weekly
The Complete Weekly Roundup of SQL Server News by SQLServerCentral.com
Hand-picked content to sharpen your professional edge
Editorial
 

All the Tools in Your Toolbox

I recently began writing an article to compare the performance of several window functions to traditional query methods. I began with my favorite function, LAG, but soon found that there were so many other ways to write the query that the article never covered the additional window functions.

The article was quite fun to write, and I learned that using a temp table to pre-aggregate the rows improved the performance of all other methods. An OUTER APPLY with the indexed temp table was almost as fast as LAG. I even found that a cursor was faster than several of the methods that I tried.

At first, I hesitated to include the cursor solution in the article because I didn’t want to encourage anyone to write a cursor in place of a set-based approach. I decided to include it because it performed so much better than some of the other methods, though, I wouldn't recommended it in any case.

In my DBA days, I used cursors in some of my admin scripts to do something on each database, server, or user, for example. Many might say, use sp_MSforeachdb for databases instead, but I don’t see the difference since it loops through the databases as a cursor might. At least, I found that the cursor gave me more flexibility and worked when it had to be one action at a time. Of course, you could also use PowerShell (still loops!) for most admin tasks today instead.

Before Microsoft added several new window functions in 2012, a cursor may have been a fast solution for quite a few tricky queries. The old Speed Phreakery articles showed that there were faster solutions than a cursor back then, but they were challenging to write. That all changed in 2012 with functions like LAG and moving aggregates.

Over the years, I’ve heard things like “just turn it into a table-valued function” or “APPLY is always faster than a join,” or “never use a CTE if you care about performance.” Like everything else in the database world, it depends. Even your least used T-SQL method is still a tool in your toolbox. It may be rusty from disuse, but it's there when you need it.

As my article demonstrated, there can be many ways to solve a problem without getting stuck with one methodology. If one way has poor performance, there are likely other techniques you can try.

 

Kathi Kellenberger

Join the debate, and respond to the editorial on the forums

 
The Weekly News
All the headlines and interesting SQL Server information that we've collected over the past week, and sometimes even a few repeats if we think they fit.
Vendors/3rd Party Products

What's the real story behind the explosive growth of data?

IDC’s recent Global DataSphere Forecast, 2021-2025 predicts that global data creation and replication will experience a compound annual growth rate of 23% over the forecast period. But what’s causing the growth? Where will all of that extra data be stored? And how should we, as data professionals, prepare for it? Read this blog to explore these important questions.

Administration of SQL Server

Turn On Trace Flag 3226

From Callihan Data

A few days ago, we looked at how to check for enab...

Database Sizes

From SQLStudies

Quick query today. I needed a list of database siz...

Building blocks of Extended Events data collection

From Simple Talk

Extended Events have been part of SQL Server since...

Impact of TDE (Transparent Data Encryption) on Tempdb databases

From SQLShack

This article will explain the impact of TDE (Transparent Data Encryption) on one of the crucial system databases, tempdb. Everybody wants to secure their data to prevent unauthorized access...

CheckDB Chat with Steve and Derrick

From Steve Stedman

Steve Stedman 0:15 So Derrick, one of the things we run into is customers who are a little bit resistant to running CheckDB as frequently as maybe we think...

Azure DevOps

T-SQL Tuesday 142 – Introducing my Azure DevOps templates for Data Platform deployments

From Kevin Chant

Reading Time: 3 minutes For my T-SQL Tuesday cont...

Azure SQL Database

Identify and remediate non-compliant Azure SQL Databases for auditing on SQL Server

From SQLShack

This article explores the Azure built-in policies ...

Azure Alerts for creating, modifying and deleting Azure SQL Databases

From SQLShack

This article will explore the Azure alerts configu...

Azure SQL Managed Instance

How-to determine the SQL MI Failover Group configuration

From Azure SQL

Continuing the topic of High Availability from the...

Creating Azure SQL Managed Instance

From SQLServerCentral Blogs

First step login into the Azure portal and find SQ...

Azure SQL Managed Instance – Terraform command available

From Azure SQL

We continue investment into #sqlmiops, and after r...

Computing in the Cloud (Azure, Google, AWS)

How to Join Windows 10 to Azure Active Directory

From Petri IT Knowledgebase

Registering Windows 10 devices with an identity pr...

Conferences, Classes, Events, and Webinars

Data Community Summit 2021 Pre-cons

From DCAC

The team at DCAC is proud to say that we have memb...

DMO/SMO/Powershell

#PowershellBasics: Running a .sql script file.

From SQLStudies

As with all programming tasks there are a number o...

Fun With PowerShell Pipelined Functions

From Arcane Code

Introduction In my previous post, I covered the us...

How to add members to the Administrators group with Powershell

From SQLServer-DBA.Com

An Adminstrator asked how to use Powershell for adding members to Local Administrator group

DevOps and Continuous Delivery (CI/CD)

Increase in demand for Data Platform automation

From Kevin Chant

Recently I have taken part in various discussions about why there is an increase in demand for Data Platform automation...

DevOps or ‘DevOops’: Three Tips for Successful DevOps

From Past News - RSS Feeds

Throughout my career as an IT consultant, working ...

ETL/SSIS/Azure Data Factory/Biml

Executing stored procedures from data pipelines in Azure Data Factory

From SQLShack

This article aims to walk you through the process ...

Performance Tuning SQL Server

SQL Server Stored Procedure Recompile Options

From SQLShack

This article intends to give comprehensive details...

SQL Server Latches – Other Latches To Know About

From SQLPerformance

Paul Randal closes out his series on latch bottlen...

Rewriting The Query Tuning Book

From Scary DBA (Grant Fritchey)

While I have not yet signed the contract, I have s...

PowerPivot/PowerQuery/PowerBI

How to connect to a Power BI Premium Per User using SQL Profiler

From FourMoo

I was recently looking on how to use SQL Profiler ...

How to show a name more than once in Power BI

From Guy in a Cube

Ever run into an issue where a duplicate name does...

Create a Single Source of Truth With Power BI & Power Automate

From BlueGranite Blog

In the world of modern technology, we can all unde...

Preserving Data Types With SQL Queries In Power Query And Power BI

From Chris Webb's BI Blog

My post earlier this year on enabling query foldin...

Python

Getting started with the Azure Queue Storage using Python

From SQLShack

In this article, we are going to talk about the Az...

R Language

Little useless-useful R functions – Useless analog and digital clocks

From TomazTsql

It is all about measuring time using useless clocks. Script takes a system time and displays any given clock in a rather “static” way. You can choose between analog,...

Replication

Replication Deadlocks

From Erik Darling Data

Replication is one of my least favorite thi...

Reporting Services

SSRS IIF, Switch and Choose Functions for Dynamic and Appealing Reports

From MSSQL Tips

Learn how to use IIF, Switch and Choose logical functions in SSRS reports to make your reports more dynamic and more appealing to report users.

SQL Server News

SQL Server 2017 Cumulative Update 26

From Glenn Berry

SQL Server 2017 Cumulative Update 26 On July 12th,...

T-SQL

How to Partition a SQL Server Table with a Columnstore Index

From MSSQL Tips

In this article we cover how to setup partitioning...

Learn how to convert data with SQL CAST and SQL CONVERT

From MSSQL Tips

Learn how to convert SQL Server data to different data types such as string, date, integer and numeric using the CAST and CONVERT functions.

Deleting Duplicate Records

From Callihan Data

Have you ever needed to delete duplicate records f...

Nested CTEs

From Steve Stedman

Russian Nesting Dolls If you have ever seen the Ma...

Persist Sample Percent in SQL Server IS Fixed!

From SQLServerCentral Blogs

Hi Everyone, this is John Sterrett. I am a SQL Ser...

Tools for Dev (SSMS, ADS, VS, etc.)

SQL Server Data Tools (SSDT)

From SQL Server – {coding}Sight

Any SQL Server DBA, Developer, or end-user always ...

Virtualization and Containers/Kubernetes

AD(Active Directory) authentication for SQL Containers on Azure Kubernetes Service (AKS)

From MS SQL Server Blog

In this blog today, let's configure AD (Active Dir...

 
RSS FeedTwitter
This email has been sent to {email}. To be removed from this list, please click here. If you have any problems leaving the list, please contact the webmaster@sqlservercentral.com. This newsletter was sent to you because you signed up at SQLServerCentral.com. Note: This is not the SQLServerCentral.com daily newsletter list, and unsubscribing to this newsletter will not stop you receiving the SQL Server Central daily newsletters. If you want to be removed from that list, you can follow the instructions on the daily newsletter.
©2019 Redgate Software Ltd, Newnham House, Cambridge Business Park, Cambridge, CB4 0WZ, United Kingdom. All rights reserved.
webmaster@sqlservercentral.com

 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -