Question

From a comment on https://stackoverflow.com/a/11064/247702

You save the query planner from needing to figure that out by using either Answer.Text or a.Text. It doesn't matter whether you use the table name or the alias, but qualifying the field helps.

Is this true for SQL Server 2008 when querying a single table? For example, will this

select
    mt.myfield
from
    mytable mt
where
    mt.myid = 1

be faster than this?

select
    myfield
from
    mytable
where
    myid = 1

I could test this ofcourse, but I don't have a large enough dataset nor do I know how to reliably test SQL Server performance.

Était-ce utile?

La solution

In the case that you presented I think it would be the same thing.

The only problem might be when you join with multiple tables and the query optimizer needs to locate the column in the where clause (in all the tables). If you use aliases the query optimizer already knows to what table each column is.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top