ITable.ForeignKeys

Fore Syntax

ForeignKeys: ITableForeignKeys;

Fore.NET Syntax

ForeignKeys: Prognoz.Platform.Interop.Db.ITableForeignKeys;

Description

The ForeignKeys property returns a collection of table external keys.

Comments

Use the ITableForeignKeys.Add method to create external key.

Fore Example

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

Add links to the Metabase, Db system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    Table: ITable;
    FKeys: ITableForeignKeys;
    Key: ITableForeignKey;
Begin
    mb := MetabaseClass.Active;
    Table := mb.ItemById("TABLE_L").Edit As ITable;
    FKeys := Table.ForeignKeys;
    FKeys.Clear;
    Key := FKeys.Add;
    Key.Columns := "FK";
    Key.RTable := "TABLE_F";
    Key.RColumns := "ID";
    Key.IsCascade := True;
    Key.AlterType := DbAlterType.None;
    Key.ComparedWith := 0;
    (Table As IMetabaseObject).Save;
End Sub UserProc;

After executing the example the FK field of the TABLE_L table is an external key on the ID field in the TABLE_F table.

Fore.NET Example

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

Imports Prognoz.Platform.Interop.Db;

[STAThread]
Public Shared Sub Main(Params: StartParams);
Var
    mb: IMetabase;
    Table: ITable;
    FKeys: ITableForeignKeys;
    Key: ITableForeignKey;
Begin
    mb := Params.Metabase;
    Table := mb.ItemById["TABLE_L"].Edit() As ITable;
    FKeys := Table.ForeignKeys;
    FKeys.Clear();
    Key := FKeys.Add();
    Key.Columns := "FK";
    Key.RTable := "TABLE_F";
    Key.RColumns := "ID";
    Key.IsCascade := True;
    Key.AlterType := DbAlterType.daNone;
    Key.ComparedWith := 0;
    (Table As IMetabaseObject).Save();
End Sub;

After executing the example the FK field of the TABLE_L table is an external key on the ID field in the TABLE_F table.

See also:

ITable