17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 17: Reporting for Duty, Sir! A Look At Reporting Services<br />

Now click Finish and the Data Source view is actually constructed and added to our Report Model Project.<br />

While we now have a workable view, the view has some issues we need to deal with prior to using it in<br />

our data model; there are no formal relationships between the Product table and the other tables in the<br />

Data Source view. Let’s fix that….<br />

Manipulating Relationships Between Objects In Data Source Views<br />

While the wizard tries to put information together about our Data Source view, it has to base its<br />

information on the column names, types, and foreign key references in the table. While foreign keys<br />

are great for giving us a well-defined description of the relationship between two tables, there are often<br />

cases where there is, for some reason, a relationship that does not have a formal foreign key defined on<br />

it. In the case of the Data Source view we just created, we have no formal foreign key between Products<br />

and SalesOrderHeader (ProductSpecialOffer joins to both, and that is the only formal way they are<br />

related). The ProductID is, however, a viable join item between the two tables, so we need to add that<br />

reference to the Data Source view.<br />

Start by right clicking on our new Data Source view in the Project Explorer, and select View Designer as<br />

shown in Figure 17-11.<br />

Figure 17-11<br />

Visual Studio brings us up a visual representation of the tables involved in our Data Source view, and, as<br />

you can see in Figure 17-12, it is unaware of the relationship between SalesOrderDetail and Product.<br />

Click and drag ProductID from the SalesOrderDetail table onto the ProductID in the Product table,<br />

and <strong>SQL</strong> <strong>Server</strong> will bring up a dialog to confirm the relationship. Click OK and the relationship should<br />

now be shown (as it is in Figure 17-13).<br />

Note that the click-and-drag order to relate tables is the opposite of what is used in most diagramming<br />

tools where you establish foreign keys. In most diagramming environments, you drag from the parent<br />

table to the child; the Data Source view designer works just the opposite.<br />

525

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!