Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

10.11 Linking Tables

Linking Tables

After connecting to the data source and selecting the tables you want to print, you proceed to the second tab of the Database Expert dialog box. This is the Links tab. This tab is only available when you select two or more tables. You need to link the tables together so that Crystal Reports knows how they are related. For example, a pet store that wants to print a list of its products by animal needs to build a report using an animal table and a product table. To match the product to the appropriate type of animal, both tables will be linked by the field Animal ID. It would be impossible to determine which products are associated with which animal without this link. The Links tab, shown in Figure 10-8, is used for setting the fields that link the different tables together.



Figure 10-8. The Links tab.

When the Links tab is first displayed, it creates default links for you. In an effort to make it easier for you, Crystal Reports tries to figure out which fields in each table should be linked to each other. It does this based upon the field name, data types and indexes. This is the equivalent of Crystal’s “best guess” for the relationships between the different tables.

To get the most benefit out of the auto-arranged links, design your tables with field names that use a consistent naming convention and have well thought out indexes. This will result in a higher probability that Crystal Reports will create the appropriate default links.

The default links that Crystal creates are not set in stone. You are free to delete them or add more according to your needs. To delete a link, simply click on it (to select it) and then click on the button labeled Delete Link. You can also just press the Delete key after selecting it. To add a new link, drag and drop the field from one table onto the matching field in the other table.