SQL: Avoiding hard-coding T-SQL procedure names within procedure code

When developers are creating SQL Server stored procedures in T-SQL, I often see them embedding the name of the procedure as a hard-coded string within the procedure itself. Here's a rough example:

The problem here is that if the procedure gets renamed, you then need to go and find every reference to it throughout the code.

The solution is to get the procedure name programmatically and use that:

Note that although I tend to use PascalCase for variable names, I consider names like this to be more like constants within the code, and for that reason I use SCREAMING_SNAKE_CASE (ie: all capitals with underscores).


Leave a Reply

Your email address will not be published. Required fields are marked *