Show contents 

Db > Db Assembly Interfaces > ITable > ITable.AlterTable

ITable.AlterTable

Syntax

AlterTable(OldTable: ITable; [Options: Integer = 0]);

Parameters

OldTable is the table structure of which should be updated according to the structure of current table.

Options is reserved parameter.

Description

The AlterTable method updates the structure of the OldTable table on database server according to the current table structure.

The information on following table elements is updated:

If the OldTable table contains elements that are not present in the current table, they are removed, if the current table contains elements that are not present in the OldTable table, they are added.

Example

Executing the example requires that the repository contains a table with the Table_1 identifier.

Sub UserProc;
Var
    MB: IMetabase;
    Table, OldTable: ITable;
    Field: ITableField;
Begin
    Mb := MetaBaseClass.Active;
    Table := Mb.ItemById("Table_1").Edit As ITable; // table, which structure will be used for update
    OldTable := Mb.ItemById("Table_2").Bind As ITable; // table, which structure on database server will be updated
    Table.NativeName := OldTable.NativeName; // set equal physical names temporarily
    // It is required for saving uniqueness of physical name of OldTable table
    Field := Table.Fields.Add; // Add a time field, which will be created in updated table
    Field.Id := "NewField";
    Field.DataType := DbDataType.String;
    Field.Size := 20;
    Table.AlterTable(OldTable);
End Sub UserProc;

After executing the example, the table structure on a database server, referenced by repository table Table_2, is updated. The structure is set according to structure of the table, to which the repository table Table_1 refers, and also one new text field NewField is added.

See also:

ITable