Quick Tips–SQL Prompt Custom Aliases
I love SQL Prompt, and think it’s a great productivity tool. Even before I worked at Red Gate, I love the tool and had a copy before Red Gate bought the technology from the original developer. Recently I’ve run into a few people that weren’t aware of some of the ways in which it can help you. This is a quick look at one of the ways I use SQL Prompt.
SQL Prompt can automatically create aliases for tables. However, as I’ve worked on different systems, I’ve often found that development teams like to use specific aliases consistently to ensure that everyone can easily read the code and understand which tables are being queried.
Suppose I decide that I have these tables:
- Product Details
I often use these tables in queries in my system, and I want to have consistent aliases. Right now, I could have these two queries with the default SQL Prompt alias settings:
Note that the Orders table has “O” as an alias in the first query, but “O2” as an alias in the second query. This isn’t an issue when I’m writing a query, but when I revisit this code in a month or two and add an enhancement, it can be tricky.
What I’d like to do is ensure I had consistent aliases for my tables, so that every developer always knows that “o” is Orders and “od” is OrderDetails. I want these aliases
- Product – P
- Product Details – PD
- Orders – O
- OrderDetails – OD
I can do that in SQL Prompt with custom aliases. Let me go back to the Options dialog and select Aliases.
I’ve already added an item in the Custom aliases section for the product table. However I can click New (highlighted above) and I’ll get a little dialog.
I repeat this process for each table, and soon I have all four entered.
Now I can rewrite my query. I start typing each table, and once it’s highlighted, click “tab”. When I get done, I have:
A quick way to ensure that all of your tables are consistently aliased, no matter in which order you type things.