ForeignKeys: ITableForeignKeys;
The ForeignKeys property returns a collection of table external keys.
Use the ITableForeignKeys.Add method to create external key.
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.
See also: