SQLServerCentral Editorial

Who Still Uses SP_ for Naming?

,

An interesting post recently from Chad Callihan on the reasons why someone shouldn't use sp_ to prefix their stored procedures. This is advice that I've seen for years, but I haven't run into this lately with many customers. It seems I do see some usp_, but not sp_. I think that's good, and if you're not sure why, read Chad's post.

I think my main reason for not doing this is that I sometimes create procs in master. Not because it's a good idea (it isn't) or I want to, but because I'll make mistakes. I'll accidentally connect to master and deploy a script, because I'm not paying enough attention. Usually, I'll catch this right away, but if not, soon after I've told a client things are working, they'll let me know they aren't. Then I connect to the right database.

In a vacuum, or even as you sit reading this today, it's easy to criticize someone else for making the mistake of connecting to the wrong database, or even forgetting to delete the object in master after I've created it in the right one. However, all of us are human. We'll make mistakes. We'll be pressed for time or sick or tired or want to leave or some other situation where we aren't using all of our faculties. Even if none of those are true, we might depend on muscle memory because we've done this 1,000 times (or may 12 times in the last hour) and then don't notice we've connected to the wrong database.

What might be even worse if when we're updating objects and potentially update in one place but not another. What if v7 of the proc is in the user database, but v5 is in master. Who knows if we (or the client) will notice things aren't working as expected right away.

Mistakes are one of the reasons I try hard to get everyone to follow a DevOps approach. Put your code in version control (so you know where it is when you make mistakes), use automation and CLI calls to deploy code. Whether you use something like Flyway or your own SQLCMD scripts, make sure things are automated. Then ensure you have logs with commands run, and if needed, output from the scripts.

We're human, we make mistakes, so figuring out how to automate a process and then ensuring that automation is running results in repeatable, reliable deployments. Something we should all want, especially the control-obsessive DBAs.

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating