Alias Flashcards
When aliasing a table, what should you assign as the alias?
The alias should be short. Usually one letter that is somehow indicative of the table. For example, Employees table could be aliased as E.
SQL Server 70-461 02-01
If you alias a table, can you still use the real table name in the query?
No, once you alias a table in a query you must use the alias whenever you are referring to the table.
For example, SELECT Employee.Last_Name will give an error. You must use SELECT E.Last_Name, since E is the alias you assigned to the employee table in the from clause.
SQL Server 70-461 02-01
What are three options for assigning an alias to expressions that define the result attributes in the SELECT clause and which is the best option?
- expression_name AS alias_name
- expression_name alias_name
- alias_name = expression_name
The best option is number 1. It is the most readable.
SQL Server 70-461 02-01
Describe an example of how using the alias naming convention alias_name expression_name can go wrong.
Say the author of a query desires the columns firstname and lastname and forgets to put a comma between the two in the SELECT clause. The query will return the firstname with an alias of lastname.
SQL Server 70-461 02-01
What are two reasons you might use an alias for an attribute?
- If you need the result attribute to have a different name. For example, employeeid instead of empid.
- To assign a name to an attribute that results from an expression that would otherwise be unnamed. For example, firstname + Nā ā + lastname.
SQL Server 70-461 02-01