NOTE 258 Part I EXAM PREPARATION This is
NOTE 258 Part I EXAM PREPARATION This is an example of using table aliases. When you re doing complex joins, and you don t want to type the table name over and over again, you can alias the table to a different name. In this case, the Person table is aliased to P. After doing that, the only way you can access column names in the Person table is by using the P alias. You can t mix aliased and non-aliased names, so this does not work: SELECT A.* FROM Person P INNER JOIN Sales S ON P.PersonID = S.PersonID INNER JOIN PersonAddress PA ON PA.PersonID = P.PersonID INNER JOIN Address A ON PA.AddressID = A.AddressID If you attempt to run that query, you get an error that says, the column prefix Person does not match with a table name or alias name used in the query. That s because you aliased the table name to something else, so SQL Server can t use the real name for it anymore; it can use only the alias. Another form of table aliasing syntax is SELECT A.* FROM Person AS P INNER JOIN Sales AS S ON P.PersonID = S.PersonID INNER JOIN PersonAddress AS PA ON PA.PersonID = P.PersonID INNER JOIN Address AS A ON PA.AddressID = A.AddressID The AS keyword is always optional, and if the point is to type less by Using Aliases Effectively You should using aliases, it should probably be left out. use aliases that somehow abbreviate On the topic of optional syntax, the keyword INNER is not required the table name in some consistent in the queries, either. If you want to write the query as follows, it and standard way. For example, don t alias the first table as A, the second works the same way: table as B, and so on, because you ll SELECT A.* spend more time figuring out what the FROM Person P JOIN Sales S aliases mean than it would have ON P.PersonID = S.PersonID taken to type in the full names in the JOIN PersonAddress PA first place. You should carefully mea-ON PA.PersonID = P.PersonID sure tradeoffs between readability and JOIN Address A ON PA.AddressID = A.AddressID brevity, and if you have to guess, lean toward readability. Arguably, this example requires less typing, but many people feel that the keyword INNER provides a little more insight into how the query works and is easier to read.
For high quality website hosting services please check cheap web hosting website.