Check Those Aliases

Kevin Feasel

2017-06-02

T-SQL

Erik Darling warns you about accidentally using the wrong alias in a query:

People will often tell you to clearly alias your tables, and they’re right. It will make them more readable and understandable to whomever has to read your code next, puzzling over the 52 self joins and WHERE clause that starts off with 1 = 2. It can also help solve odd performance problems.

Take this query, for instance.

This isn’t just for subqueries; even simple joins can go haywire when you accidentally use the wrong alias and both tables happen to have the same column name.

Related Posts

Your Reminder Not To MERGE

Kevin Wilkie points out the numerous problems with the MERGE operator: Now, when I last posted, I’m sure you thought I was done talking about the MERGE statement. You are so wrong, compadre! One more post is absolutely needed! There are a few issues with the MERGE statement. Well, as of this writing, there are 361 possible issues according […]

Read More

CROSS APPLY Replacing REPLACE

Bert Wagner shows off a good use of the APPLY operator: Here we only have 4 nested REPLACE functions. My shameful record is 29. I’m not proud of it, but sometimes it’s the only way to get things done. Not only are these nested REPLACE() functions difficult to write, but they are difficult to read […]

Read More

Categories

June 2017
MTWTFSS
« May Jul »
 1234
567891011
12131415161718
19202122232425
2627282930