Bert & Pinal Troubleshoot a Slow Performing SQL Server

Published on: 2018-11-13

What happens when you run into performance tuning expert Pinal Dave?  Talk about how to troubleshoot a slow performing SQL Server of course!

This week is all about the video, so if you can’t view it above, head on over to my YouTube channel to watch it there.

After watching, be sure to check out Pinal’s free performance diagnostic scripts over at SQLAuthority.com:



Thanks for reading. You might also enjoy following me on Twitter.

Want to learn even more SQL?

Sign up for my newsletter to receive weekly SQL tips!

Learning New Skills

Published on: 2018-11-06

This post is a response to this month’s T-SQL Tuesday #108 prompt by Malathi Mahadevan.  T-SQL Tuesday is a way for the SQL Server community to share ideas about different database and professional topics every month.

This month’s topic asks to share how we learn skills other than SQL Server.


I enjoy learning to do new things; there’s a major sense of accomplishment I feel when I can tell myself, “Wow, I went from knowing almost nothing to being able to have this new skill.”

Over the years I’ve realized I’m pretty consistent in how I go about learning something new, so what follows is my process for learning a new skill.

What I Am Learning

Recently, my non-SQL Server related learning goals have been to learn to use plain old vanilla JavaScript.

In this case I’m not necessarily starting from nothing (I have been writing JavaScript for close to 20 years now…) but previously where it was necessary to use a library like jQuery to get any kind of compatibility and consistency across browsers, the time has finally come where the JavaScript (ECMAScript) standard is mostly implemented correctly in most modern browsers.  No more need for large helper libraries!

And so the appeal here is that if I can ditch the overhead of a large library, my code will be simpler, easier to maintain, and faster to load and execute.

Steps to Learning a New Skill:

1. Commitment

For me, the hardest part to learning a new skill is time management: if I don’t make time for it, it won’t happen on its own.

I think the easiest way to make time to learn a new skill is to incorporate it into a project at work.  By aligning it with your day job, you’re guaranteeing some time to work on it most days.  Yes, critical projects and deadlines do come up where learning has to be set aside temporarily, but if you can find a project that doesn’t have urgent deadlines AND aligns with learning goals, then you’ll be good to go.

For me, learning vanilla JavaScript is a great “at-work” project since I’m already developing a lot of web apps with JavaScript anyway – the main difference is I’ll be using the standard JavaScript functionality instead of working through a library like jQuery.

Now obviously this won’t work in all scenarios: if you want to learn to build drones and you do development work for a chain of grocery stores, you probably can’t figure out a way to align your interest with work (unless of course your company is trying to build out a drone delivery service).

Inthat case, you need to set aside time at home. This essentially comes down to your own discipline and timemanagement.  The key here is that youneed to set up time regularly and set yourself deadlines.  Instead of having the deadline of a workproject to help motivate you to learn, you need to tell yourself “I’mgoing to get this chunk of plastic and copper wiring up in the air by the endof the month” and try to deliver on that goal.

2. Go Cold Turkey

This is the hardest part of kicking any old habit.  Ideally when learning something new, I like to use it exclusively in all scenarios where I can.

This may not always be possible: sometimes there is a deadline you have to meet and trying a new skill that slows you down is not always the best idea.

But even if that’s your scenario, pick at least one project to go completely cold turkey on for learning your new skill.  Going cold turkey on a project will force you to work through the hurdles and actually learn the necessary skills.

Thiscan be challenging.  I have the jQuerysyntax and methods ingrained in my brain from years of use; switching to usingstandard JavaScript is tough because I’m frequently having to look up how to dothings.  But if I picked the rightproject (ie. one without urgent deadlines), then this becomes a fun learningexperience instead of something stressful.

3. Build a Collection of Resources

The internet is awesome: it contains nearly all of the information you could ever want for learning a new skill.  The internet can also be a terrible place for learning a new skills if used incorrectly.

When learning something new, I try to find resources that guide me through a topic.  Whether it’s a book, a website with a structured guide, a video course, or documentation with clear examples, it’s important to find something that will teach you the why as well as the how.  I prefer using something with structure because it helps me learn the fundamentals correctly.

With my JavaScript learning, I have been enjoying the guides and daily newsletter at https://vanillajstoolkit.com/ .  That site also has clear documentation for the most common features.  The “official” documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) is good to reference too, but can be overwhelming when first starting out.

What I don’t like doing is searching for each question I have on StackOverflow.  Don’t get me wrong, I love StackOverflow, but when learning some brand new skill I don’t think it always provides the best answers.  Sometimes you get good answers, but sometimes you’ll come across answers that, while technically correct, apply to some edge case, old version of a language, etc… that make them less-than-helpful when learning a new skill.

4. Document and Share

As I learn, I document what I learn.  This could be as simple as code snippets that I find myself using all the time, or it could be links to additional helpful resources.

Eventually I like writing up what I’m learning.  Even if no one reads it, summarizing your thoughts and ideas will help clarify and retain them better.  A summarized document or blog post also provides an additional reference for you to use if you need to in the future.

I haven’t been blogging publicly about my JavaScript learning, but I have been taking notes and sharing with individuals who are learning along with me.

5. Rinse and Repeat

That’s it!  On my first pass at learning a new skill I try to finish a small project to get some immediate satisfaction.  I then pick a new project that’s a little bit more ambitious, but still be manageable because I now have some knowledge that I didn’t have before starting my first project.

Baby steps.  A little bit each day (or every other day).  Do it enough times and eventually you find yourself being fully capable of whatever skill you set out to learn.

Thanks for reading. You might also enjoy following me on Twitter.

Want to learn even more SQL?

Sign up for my newsletter to receive weekly SQL tips!

The 5 Scariest Moments for a SQL Server Developer

Published on: 2018-10-30

While families and friends are scaring each other this Halloween week with stories of ghosts and ghouls, I thought it’d be way scarier to talk about truncate tables and source control.

Accidental Data Deletion

You’ve spent all morning loading millions of records into your tables.  Some of that data was painstakingly loaded by hand from flat files, and some lookup values you even authored manually because “you’ll only have to do this once.”

You are jumping around between SSMS windows, running this query here and that query there, pressing F5 like there’s no tomorrow. And then right before you press to F5 to finish all of your work…

…you realize that you ran the whole tab worth of code instead of the one statement you meant to highlight.  “Commands completed successfully” flashes in your Message window, and in horror you discover you accidentally ran a truncate table statement!

Ok so this is pretty bad.

You know backups are being taken but…can the DBA restore the most recent data you spent all morning working on?  You tell her about your misfortune (“…yeah one of my coworkers accidentally deleted the data…”) and hold your breath.

After a few minutes she gets back to you saying everything is back up and working.  Saved by good backup practices…this time!

Problems With code You Inherited

You receive an instant message from your DBA.

DBA: “Hey <your name here>, how are you doing?

“You: “Good how are you?”

DBA: “Look, the instance XYZ has been at 100% CPU utilization for the past hour.  I see you have that has been running that whole time….and it’s using a scalar function.

You: “…”

You: “Sorry.  I am just running this job for Bill since he left a few weeks ago.  Obviously there are some problems with the way he was writing some of this queries and I haven’t had a chance to look them over yet.”

DBA: “That’s ok.  I know you would never write a scalar function that totally destroys the server.  Anyway, I was able to easily rewrite the query into a table-function that should run a lot more efficiently.  Is it ok if I kill your original query and run this new one instead?”

You: “Yeah sure, that’d be great.  Thank you!”

Missing Index Details

You’ve been having a good day: no outages, no annoying customer requests, and the only thing keeping you from going home is to finish tuning the query you are working on.

You execute your query after making all necessary changes and…nothing.  The executing query icon just keeps spinning, and spinning, and spinning…

You go grab some water, and by that time the query has finished.  You switch over to the Execution plan tab and…you see SQL Server’s Missing Index hint recommending that you create an index.

Now don’t be confused, this text looks green and friendly.  You might be tempted to follow the recommendation and add the missing index it recommends – but don’t! 

That siren song of easy query tuning will steer you straight into the rocks known as unnecessary index maintenance. 

Just before you execute Microsoft’s missing index details script, you realize that if you add some include columns and reorder a couple of the key columns, you’ll have an index that will be applicable to all of your table’s queries.

You avoid getting ship wrecked and create an index that useful for more than just this one query – phew!

Email Subjects That Read: “Does anyone know why none of my queries are running?”

Last night’s data load failed.  “No big deal,” you assure yourself. “I’ll just run it now – no one will know the difference.”

You kick-off your ETL queries and decide to go make some oatmeal.  At your office’s kitchen you run into a coworker you haven’t seen in a while, and you get to talking about work, life, that weekend’s football game that was lost in overtime…that’s been happening a lot this season, huh?

On the way back to your desk, one of your customers stops you to ask some questions, your manager needs to discuss project planning with you, a new employee is introduced, etc…

By this point the office is busy with activity.  You finally make it back to your desk MUCH later than you originally intended.  What were you doing again?

You can’t remember so you decide to check your email.  You notice a chain emails asking “Does anyone know what’s going on with server ABC?” Things are running so SLOW!  I can’t run even the simplest queries!”

OH CRAP you think.  You look at your load process queries and they are still running with no end in sight.  Do you kill the queries and wait for the hour-long rollback to complete or…

…just then your queries finish.  A minute later you receive another email saying “seems like everything is working fine now.” 

Another bullet dodged.

Where Did My Code Go?

Working on this team project has been a fun experience for you – responsibilities have been shared and you and your coworkers have been delivering on deadlines ahead of schedule.  You’ve never been able to write queries and make progress to the end product as quickly as this.

You sit down to start working and remember that you had to debug a query from yesterday afternoon.  You go and open the stored procedure in dev and…… it’s not the same query anymore.

Sure, parts of it are the same, but there are some extra parameters and some of the logic has changed.  What the heck…?

“Did anyone mess with USP_GetProducts since yesterday?” you ask your alley of teammates.

“Uhh…I updated it this morning to make it work for my business logic requirement,” said intern Sam.  “Is something wrong?”

“Well, it’s totally different from the way I had it when I left yesterday evening.  I bet we got out of sync and the merge conflict wasn’t resolved correctly” you say.

“Oh yeah, I got some message about merging.  I just clicked the ‘keep my version’ button,” says Sam.

“No big deal,” you say with confidence.  “I can pull my version out of source control.  Come on over and I can show you how we can merge both of our queries together.”

Source control saves the day.

Happy Halloween.

Thanks for reading. You might also enjoy following me on Twitter.

Want to learn even more SQL?

Sign up for my newsletter to receive weekly SQL tips!