ITableForeignKey.RTableObject

Syntax

RTableObject: ITable;

Description

The RTableObject property determines the table to which the external key refers.

Comments

To create external key use the ITableForeignKeys.Add.

Example

Executing the example requires tables with the TABLE and TABLE_FK identifiers in repository. The TABLE table must contain the primary key with the ID identifier. The TABLE_FK table must contain an integer field with the FK identifier.

Add links to the Db and Metabase system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    Table, TableFK: ITable;
    FKeys: ITableForeignKeys;
    Key: ITableForeignKey;
Begin
    // Obtain a repository
    mb := MetabaseClass.Active;
    // Obtain a table
    Table := mb.ItemById("TABLE").Edit As ITable;
    // Get second table
    TableFK := mb.ItemById("TABLE_FK").Edit As ITable;
    // Obtain a collection of external keys of the "TABLE" table
    FKeys := Table.ForeignKeys;
    // Delete external keys of the "TABLE" table
    FKeys.Clear;
    // Add external key to the "TABLE" table
    Key := FKeys.Add;
    { Set the "FK" field of the "TABLE_FK" table as external key
      "TABLE" table }

    Key.Columns := "FK";
    Key.RTableObject := TableFK;
    Key.RColumns := "ID";
    // Save changes
    (Table As IMetabaseObject).Save;
End Sub UserProc;

After executing the example the FK field of the TABLE_FK table is an external key for the TABLE table.

See also:

ITableForeignKey