Alias Flashcards

1
Q

When aliasing a table, what should you assign as the alias?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If you alias a table, can you still use the real table name in the query?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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?

A
  1. expression_name AS alias_name
  2. expression_name alias_name
  3. alias_name = expression_name

The best option is number 1. It is the most readable.

SQL Server 70-461 02-01

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe an example of how using the alias naming convention alias_name expression_name can go wrong.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are two reasons you might use an alias for an attribute?

A
  1. If you need the result attribute to have a different name. For example, employeeid instead of empid.
  2. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly