ITable.CreateTable

Syntax

CreateTable;

Description

The CreateTable method creates a table on database server by available metadata.

Comments

A physical table created on database server corresponds to each object of the Table repository. The table is automatically created on database server on creating and saving of repository table.

The method creates a physical table on the server by existing description of the repository table. The method use is relevant, if there is no need to create corresponding object in repository.

NOTE. The method is automatically called on creating and saving repository table.

Example 1

Example of creating a table in repository:

Executing the example requires a repository database with the BD identifier.

Sub UserProc;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    Table: ITable;
    Field: ITableField;
Begin
    MB := MetabaseClass.Active;
    //Information for object creation
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_TABLE;
    CrInfo.Id := "New_Table";
    CrInfo. Name : =  "New table";
    CrInfo.Parent := MB.Root;
    //Creating temporary object. After change of parameters the table is saved
    MObj := MB.CreateObject(CrInfo).Edit;
    Table := MObj As ITable;
    Table.Database := Mb.ItemById("BD").Bind As IDatabase;
    Table.NativeName := "New_Table";
    //Creating description of one field
    Field := Table.Fields.Add;
    Field.DataType := DbDataType.String;
    Field.Id := "Text_Field";
    Field.Name : =  "Text field";     Field.Size := 50;
    //Saving repository table
    //Table is automatically created on the DB server at saving
    MObj.Save;
End Sub UserProc;

After executing the example, a new table is created in repository root. Corresponding table is created on database server on saving repository object.

Example 2

Example of a table creation on database server without creating corresponding repository object:

Executing the example requires a repository database with the BD identifier.

Sub UserProc;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    MObj: IMetabaseObject;
    Table: ITable;
    Field: ITableField;
Begin
    MB := MetabaseClass.Active;
    //Information for object creation
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_TABLE;
    CrInfo.Id := "New_Table";
    //Creating temporary object
    MObj := MB.CreateObject(CrInfo).Edit;
    Table := MObj As ITable;
    Table.Database := Mb.ItemById("BD").Bind As IDatabase;
    Table.NativeName := "New_Table1";
    //Creating description of one field
    Field := Table.Fields.Add;
    Field.DataType := DbDataType.String;
    Field.Id := "Text_Field";
    Field.Name : =  "Text field";     Field.Size := 50;
    //Creating physical table on DB server
    //by existing description of repository table
    Table.CreateTable;
End Sub UserProc;

After executing the example, a new table containing one field is created in database on a server.

See also:

ITable