September 20, 2017 by Kenneth Fisher
- I told you not to use NOLOCK even though I use it sometimes.
- I told you not to shrink databases, even though I do it when I need to.
- I told you not to use SELECT * but I use it all the time.
- I’ve told you not to use cursors but I like them.
You’ll hear a lot of rules and best practices from senior IT people (not just data folks, all of them). You’ll also then see those same people do what they told you not to.
That doesn’t seem fair, does it?
It is and it isn’t. Take NOLOCK as an example. I tell people “Don’t use NOLOCK”. In fact, I’ve done a number of rants about it. But I do use it every now and again. Want to know the difference? I know when NOLOCK is appropriate.
Tools are just that, tools. They can be useful or they can cause damage if you don’t know how to use them. Some tools get misused so frequently that senior IT people start telling everyone “do not use” because the chances of them being used correctly are slim, and conversely the chances of them being misused are great.
The simple answer is to just explain how to use the tools correctly right? In a perfect world, yes; that would be the correct thing to do. Unfortunately, not everyone understands what you are teaching. And certainly not everyone understands it the first time, or the second, or the third etc. Not because they aren’t smart enough, or not paying enough attention, but because it’s the nature of learning.
Let’s say I explain to someone how to use a cursor, because hey, even in a batch environment we do need loops sometimes. Then a few weeks later I realize they have started using cursors all over the place, performance is tanking, and they are now getting in trouble. Now I feel terrible. And in some cases, I (and cursors) get blamed for things not going well. It would have been easier in the long run, and safer, if I’d never shown them the tool in the first place.
So when you hear “Do not use this tool” from someone who really understands it, it’s probably because it’s a tool that gets misused far too often for the comfort of the person talking. In my opinion, at this point, you want to find out why using this tool is a bad idea. Find out what it’s used for and when it’s appropriate to use it. Once you are sure you have all that down, then, under the right circumstances, you can use the tool.
On the other hand, if you hear “Do not use this tool” from someone who doesn’t understand it, it may very well be that they have tried to use it incorrectly and run into problems. At this point you want to find out why (and/or if) using this tool is a bad idea. Find out what it’s used for and when it’s appropriate to use it. Once you are sure you have all that down, then, under the right circumstances, you can use the tool.
Ok, all of that said, there are things you shouldn’t ever do. The trick here is again, learning. Granting everyone sysadmin on a SQL instance really is a bad idea. Don’t do it. Learn why, when, and where sysadmin should be granted. And then when you have you’ll realize you still shouldn’t be granting it more than absolutely necessary.