Database Reference
In-Depth Information
, StoreKey
, SalesQuantity
FROM DWPubsSales.dbo.FactSales
JOIN DWPubsSales.dbo.DimTitles
ON DWPubsSales.dbo.FactSales.TitleKey = DWPubsSales.dbo.DimTitles.TitleKey
When this query is run, you receive data not only from the FactSales table, but also the DimTitles table,
as shown in Figure 13-2 . The database engine knows that you want data from both tables because of the JOIN
operator in the FROM clause, as well as how the tables are linked because of the ON operator that compares the title
key in both tables.
Figure 13-2. Adding the TitleId and TitleName columns to the results
notice in Figure 13-2 that we “stack” queries in the Management Studio window so to retain the previous
working version of our query as well as the new version. it is a good idea to keep multiple versions in the window,
highlighting one execute at a time. Doing so allows you to easily revert to an earlier working iteration in the event of
trouble.
Tip
It is recommended to use fully qualified names to identify your tables, but a very long query can get quite
tedious to both read and write. One solution is to use table aliases to represent fully qualified names. In Listing
13-4, you can see the use of the AS keyword to create a table alias. Using the AS keyword makes code much clearer
than creating table aliases without it. (That is in contrast to simply putting a space after the table name and then
typing in more letters to create the alias.)
 
Search WWH ::




Custom Search