This example demostrates TMySQLTable.CreateTable method used to create database tables at run-time.
mySQLTable1.TableName := 'sometable'; //table name
//integer field
with mySQLTable1.FieldDefs.AddFieldDef do
begin
Name := 'ID';
DataType := ftInteger;
Required := True;
end;
//string field
with mySQLTable1.FieldDefs.AddFieldDef do
begin
Name := 'VarcharField';
DataType := ftString;
Size := 255;
Required := True;
end;
//primary key
with mySQLTable1.IndexDefs.AddIndexDef do
begin
Options := [ixPrimary];
Fields := 'ID';
end;
//some other index
with mySQLTable1.IndexDefs.AddIndexDef do
begin
Options := [ixUnique];
Fields := 'VarcharField';
Name := 'idxForStringField';
end;
mySQLTable1.CreateTable;
See also: CreateTable method