Share via


How to: Create Table Aliases

Aliases can make it easier to work with table names. Using aliases is helpful when:

  • You want to make the statement in the SQL pane shorter and easier to read.

  • You refer to the table name often in your query — such as in qualifying column names — and want to be sure you stay within a specific character-length limit for your query. (Some databases impose a maximum length for queries.)

  • You are working with multiple instances of the same table (such as in a self-join) and need a way to refer to one instance or the other.

For example, you can create an alias "e" for a table name employee_information, and then refer to the table as "e" throughout the rest of the query.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To create an alias for a table or table-valued object

  1. Add the table or table-valued object to your query.

  2. In the Diagram Pane, right-click the object for which you want to create an alias, then select Properties from the shortcut menu.

  3. In the Properties window, enter the alias in the Alias field.

  4. Note   The SQL standard specifies that when you create an alias for a table name, you must use the alias to refer to the table in the rest of the SQL statement (that is, you cannot use the original table name). However, some databases do allow you to refer to the table by its original name. For details, refer to the documentation for your database.

See Also

Tasks

How to: Add Tables to Queries

Other Resources

Sorting and Grouping Query Results

Summarizing Query Results

Performing Basic Operations with Queries