Don't Be Lazy

Page content

Foreword πŸ”—︎

I like to help people with their SQL problems. I frequent the SQL Server community Slack channel, DBA Stack Exchange, Microsoft Q&A, etc. and challenge myself to answer questions - especially the ones where I don’t know the answer. It’s a good learning exercise.

But everyone should at least try to solve their problems first before asking for help. You cannot learn advanced debugging skills when you lack the basic ones. I usually come across these types of problems.

1. Let me Google that for you πŸ”—︎

I further divide this into two subcategories.

Microsoft Documentation πŸ”—︎

Q: What units does the total_elapsed_time column use in the sys.dm_exec_sessions DMV?

Answer: Highlight the sys.dm_exec_sessions in SSMS, press F1 and it goes to the documentation page - find or scroll down to total_elapsed_time and you can see it’s in milliseconds.

Reputable sources πŸ”—︎

For example blogs, highly upvoted questions on Stack Exchange, etc.

How to clear procedure cache but only for a single database?

Answer:

  1. Open a search engine of your choice
  2. Prefix your search with mssql, tsql, sql server or some other keyword (so you don’t get some other DB engine results)
  3. Get rid of the noise words

It could look like this:

Search bar with text mssql clear cache single database

And the results:

DBA StackExchange - How to clear all plans from a single database? recommends DBCC FLUSHPROCINDB (<db_id>) which I couldn’t find in the official documentation.

DBCC FLUSHPROCINDB not found on Microsoft Docs

Another example from Pinal Dave Uses ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE.

And I’ve also found both on SqlSkills blog post by Glenn Barry. Glenn is a very reputable source, and in time, you’ll begin to recognize people providing trustworthy content.

2. Can’t be bothered to try πŸ”—︎

As an example, I’ll use the old database myth that has been busted many times

  • Truncate table is not logged / cannot be rolled back * It’s not true and it can be easily tested.

As you can see on the video, even with typos and hesitations it took me only about 2 minutes to test and debunk this.

But what about Heap vs Clustered Index. Simple vs Full recovery model, etc. Just test it. I’ve just shown you how easy it was.

Another question I have recently seen.

Does renaming the index change the stats name?

Answer:

  1. Create a table
  2. Create an index - take a note of the stats name
  3. Rename the index - take a note of the stats name
  4. Compare

I’ll leave this as an exercise for the reader. You may not even know how to create a table or check the stats name. This is the beauty of it. You learn it this way, and what you’ve learned will stay with you longer.

3. Interrogation πŸ”—︎

  • Playing 20 questions with the asker to get the full picture of the problem.
  • The XY Problem.
  • Withholding crucial information.
    • E.g. That table is not a table but a view, and it has instead of triggers.
  • Not providing the full text of an error (including error number)
  • Misleading information. Example: I have two exact databases, but my query has two different plans.
    • Spoiler alert: schema was the same, but row count and distribution were not.

You might not know what info is relevant and which isn’t but try to provide as much context as possible anyway.

4. Put in some effort πŸ”—︎

Other people want to help you, but they don’t want to solve everything for you. The least you could do is:

  • Prepare the scripts to reproduce the problem.
    • Practice creating tables and inserting data into them
  • Show you work - what have you tried so far, what problems are you running into.
  • When requesting help with query results show the expected format.
    • Sometimes, it’s easier to understand the logic from the requested output than from a text description.
  • Try to find the bare minimum of code to repeat the issue and share that instead.
    • When you have complex queries with tens of joins and hundreds of selected columns - usually they’re not all required to debug the problem.

The message I’m trying to get across is: Help us to help you. Don’t be lazy.