Databases Reference
In-Depth Information
Note that the difference between a primary key index and a unique values index is that a
primary key is not allowed to have NULL values.
15.5 Creating a Relation
Relations are created in DAO using the CreateRelation method. The syntax is:
Set RelationVar = DatabaseVar .CreateRelation _
([ RelName [, KeyTable [, ForeignTable [, Attributes ]]]])
where:
RelName is the name of the new relation.
KeyTable is the name of the referenced table in the relation (containing the key).
ForeignTable is the name of the referencing table in the relation (containing the
foreign key).
Attributes is a constant, whose values are shown in Table 15-2.
Table 15-2. Attributes for a Relation object
Constant
Description
dbRelationUnique Relationship is one-to-one
d bRelationDontEnforce N o referential integrity
dbRelationInherited Relationship exists in a noncurrent database that contains the two attached
t ables
dbRelationUpdateCascade Cascading updates enabled
d bRelationDeleteCascade C ascading deletions enabled
15.5.1 Notes
All of the properties of a Relation object become read-only after the object is
appended to a Relations collection.
Field objects for the referenced and referencing tables must be appended to the
Fields collection prior to appending the Relation object to the Relations
collection.
Duplicate or invalid names will cause an error when the Append method is
invoked.
To remove a Relation object from a collection, use the Delete method for that
collection.
Example 15-4 illustrates the use of Relation objects. In this example, we will create a
new relation in the LIBRARY database. The first step is to create a new table, using
Microsoft Access. Call the table SALESREGIONS, and add two text fields: PubID and
SalesRegions . Then add a few rows shown in Table 15-3 to the table.
 
Search WWH ::




Custom Search