Auto alias suggestion

functional

Keep joins readable with table-name aliases that stay consistent from the first column to the last.

When you pick a table or view from completion after FROM or JOIN, SQLly can write a short, readable alias with it. The alias comes from the table's name, so you get PaymentMethod AS pm rather than a parade of t1/t2 labels.

-- type "Pay" after FROM and accept dbo.PaymentMethod
SELECT *
FROM dbo.PaymentMethod AS pm
SQLly
IntelliSense suggesting a consistent table aliasIntelliSense suggesting a consistent table alias
SQLly suggesting a table alias as a table is added to the query, then reusing it for column completion.

How the alias is built

The default style, Capital letters to lower case, works from the table name and ignores the schema:

Table nameAliasWhy
PaymentMethodpmIts capital letters, lower-cased.
Sales.SalesOrderHeadersohCapitals from the table name only.
[Order Details]odBrackets and quotes are ignored.
sales_order_headersohWith underscores, the first letter of each word.
customerscsNo capitals: the first letter plus the next consonant.
ordersor1The same rule spells or, a keyword, so a 1 is added.

Tick Include schema to put the schema's initial in front: Shared.PaymentMethod becomes spm and Sales.SalesOrderHeader becomes ssoh. The other style, Auto based on join, uses just the first letter of the table name: Customers becomes c.

Collisions and reserved words

  • Already used: if the alias is taken in the statement, a number is added. A second table that would be c becomes c2, then c3. Matching ignores case.
  • SQL keywords: whichever rule built it, an alias that would read as a keyword such as ON, OR, AS, IN, IS, BY, OF, TO, GO, AND, or FOR gets a 1 added. OrderNotes becomes on1, and orders becomes or1. If that is taken too, the usual number follows: or12.
  • Alias already typed: if an alias already follows the name, SQLly leaves it alone.

Settings

All of these are in Settings › Editor › IntelliSense and apply to every query tab:

SettingChoicesDefault
Alias namesCapital letters to lower case (with an optional Include schema), Auto based on join, or Do not suggestCapital letters to lower case, schema not included
When you accept a table or viewAdd the alias automatically, or offer it as a second suggestionAdd automatically
Include the AS keywordOrders AS o or Orders oOn

With Offer the alias as a second suggestion, accepting the table inserts just the name. The list then shows the alias on its own, labeled table alias for PaymentMethod. Press Enter or Tab again to add it, or keep typing to skip it. Do not suggest turns aliases off in both modes.

Once the alias exists

Column completion uses it automatically: type pm. and the list offers PaymentMethod's columns. Aliases are worked out from the name each time, so the same table gets the same alias in every query unless that alias is already taken.

The joins written by auto join suggestion name their new table with a first-letter alias, whatever this setting says. They use your existing aliases for the tables already in the query.