Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

The Voice of the DBA

Steve Jones is the editor of SQLServerCentral.com and visits a wide variety of data related topics in his daily editorial. Steve has spent years working as a DBA and general purpose Windows administrator, primarily working with SQL Server since it was ported from Sybase in 1990. You can follow Steve on Twitter at twitter.com/way0utwest

Quick Tips–SQL Prompt Aliases for Every Table

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.

Aliases

Aliases are used to make code more readable, and shorten the amount of code that one needs to write. Typically we use these to give a short name to a table. Instead of:

aliases_12

We could use an alias. Note the “p” after the table below and the change in the column list.

aliases_13

Automated Aliases

SQL Prompt can automate aliases for me. Under the Options dialog, there is an Aliases selection (shown below).

aliases_1

Note that I’ve checked the “Assign Aliases” box. This is not checked by default, but once I check it, I get aliases. Let me write a query.

aliases_3

I’m about to select my Orders table from the Prompt drop down. Once I click Tab, I’ll get this:

aliases_34png

SQL Prompt has added the alias for me. It’s a lower case “o”. If I add another table:

aliases_5

I hit tab at this point and I get:

aliases_6

I have a new alias of “o2”. Not terribly creative, but it works.

I have some options for changing these around. Suppose I want to make these upper case to stand out. I can change this in options:

aliases_2

Now I add a third table:

aliases_7

I hit tab:

aliases_8

My new alias is an upper case “P” for the Product table. That gives me a bit of differentiation for my tables.

I, however, do not like the “AS” keyword. I typically just space my alias after the table. I can change that in options:

aliases_9

I’ve unchecked the box and now I add a new table.

aliases_10

When I hit Tab, I’ll get a new alias, upper case, but no AS.

aliases_11

These are not terribly intuitive aliases, but this does at least clean up your code a bit, so when you see all the column names they aren’t spread way to the right with table names like “ProductDescriptions”.

aliases_14


Filed under: Blog Tagged: QuickTips, Red Gate, SQL Prompt, syndicated

Comments

Leave a comment on the original post [voiceofthedba.wordpress.com, opens in a new window]

Loading comments...