Wiki Home

Add Relations In DBC

Namespace: VB
Having trouble adding relationships between tables in a DBC. I have found it virtually impossible to set a relation between two tables contained in a DBC. Is there a way that this can be done without coding and have the relationship be permanent? -- ChrisJohnson
Relations created in a DBC are Persistent Relations. Persistent relations in a relational database are descriptive of the data model and they persist between runtimes. These relations are used as defaults in many of the visual design tools in VFP (Form designer, Report Designer, and View Designer) but they do not enforce any specific constraints on the relations that may exist at runtime.

Run time relations are referred to as Temporal Relations because they do not persist beyond the runtime session (that is they disappear when the tables are closed).

The persistent relations have two major roles in database design, they describe the nature of the data model and they are used in determining the enforcement of the referential ingtegrity constraints or "key business rules".
The trick is to create a primary index on the parent table and an index on the foreign key field in the child table. Then drag from the primary index in the parent and drop on the foreign key index in the child. Note that unlike in the Data Environment of a form or report, persistent relationships are created by dragging from index to index. -- Doug Hennig

Right Doug, but I think he was assuming that the persistent relationships in the DBC would relate the tables when he opened them without needing to code the relation.
No, relationships in the DBC are more for information purposes than anything else. Also, they are used by the RI builder. You could write code that looks at the relationships in the DBC to set the relations if you want. I am thinking Stonefield Database Toolkit might do this, but I am not sure. -- Bob Archer

Yes, I think this is one of the primary mis-conceptions new users have about relationships in dbc's. I know I struggled with it at first and most every person I've taught since has expected these relationships to be "live" when the tables are opened. I've found Select SQL or some sort of ParameterizedView often represent a better (and speedier) solution than a SET RELATION TO anyway - ?lc

Aren't the relationships defined in the DBC used in the form Data Environment? I don't use them, but I seem to remember it that way - WF

They do come over when you add related tables to the DE. However, they can be deleted from the DE, so they aren't that perminate - they are just defaults that the developer can override. -- CFK
Category Data
( Topic last updated: 2001.04.04 12:18:52 PM )