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 Main;

Var

MB: IMetabase;

Table, OldTable: ITable;

Field: ITableField;

Begin

Mb := MetaBaseClass.Active;

Table: = Mb.ItemById("Table_1").Edit As ITable; //table according to structure of which we update

OldTable: = Mb.ItemById("Table_2").Bind As ITable; //table, structure on DB server of which we update

Table. NativeName: = OldTable.NativeName; //we temporarily set identical physical names

//It is necessary to save uniqueness of phys. name of the OldTable table

Field: = Table. Fields. Add; //Adding a temporary field that later will be created in the updated table

Field.Id := "NewField";

Field.DataType := DbDataType.String;

Field.Size := 20;

Table.AlterTable(OldTable);

End Sub Main;

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