Jamie Thomson’s post T-SQL: Do you use aliases? Sparked a lively discussion inside the comment thread, with several people chiming in on pros and cons of the different ways to use aliases, whether to use them, or if fully qualified names were the way to go. I have my own preferred method which we implemented as standard at my team at Dell (for the curious, it matches Jamie’s suggestion).

That being said, books on coding standards are a dime a dozen, and if you work over any given time period on N number of projects, you will encounter just about every method with a devout developer backing up his/her methods as being most productive for a given assignment. Thankfully, the SQL alias argument is a little simpler in scope than naming conventions, error handling, etc. in C#.

I would suggest reading the post and thread, but if you are too lazy, here is a summation of the cogent points against using aliases:

  • Using aliases instead of fully qualified names can make large stored procedures hard to read as you have to find the associated alias to know where the column comes from in the database(s)
  • Aliases do not convey meaning or source as most developers use a cryptic or non-repeated pattern for aliases, ex: sys.columns uses alias a – what is the associated, why a?
  • Multiple developers on a single project will use their own rules for aliases, making one letter aliases such as c mean different things in different batches of code

All of these are very direct and considerable points. I think that most of us would agree that the end goal pertinent to this discussion is readable, maintainable and relatively self-documenting code.

In the argument for using aliases instead of fully qualified names, SSMS 2008 helps those worried about incoherent aliases not being able to identify underlying objects (hover over the alias in c.name to get the ToolTip):

You also have to love what SSMS 2008 intellisense does for making coding easier(easily available with the use of an alias, or full object name, whichever you prefer to type):

 

While this feature may not have an impact on the practices of some of the people in Jamie’s thread, it will, at a minimum, make it easier for those of us who do use aliases, and for anyone that inherits a large script.