You can create an exact copy (clone) of a data table using the CreateTable method of the database and the dictionary of the old table.
{ Use CreateTable to create a new table with the structure defined by the given dictionary. Raises an exception on failure. Parameters: aOverWrite: if true, an existing table is overwritten if it is not in use aTableName: the name of the new table aDictionary: the dictionary that defines the table and index structure See Also: DeleteTable, CreateTableEx, EmptyTable, RenameTable, PackTable, ReIndexTable, RestructureTable } procedure CreateTable(aOverWrite : Boolean; const aTableName : string; const aPassword : string; aDictionary : TnxDataDictionary; aTableScope : TnxTableScope = tsPersistent);
This will result in the new table having the exact same structure as the old one (including indexes, locales, etc). In case of an error this CreateTable will raise and exception. If you want to check the result of the operation please use the CreateTableEx method.
Example:
procedure CloneTable(aDatabase: TnxDatabase; oldTableName, newTableName: string); var oldTable: TnxTable; begin oldTable:=TnxTable.Create(nil); try oldTable.Database:=aDatabase; oldTable.TableName:=oldTableName; oldTable.Open; aDatabase.CreateTable(true, newTableName, '', oldTable._Dictionary, tsPersistent); finally oldTable.Free; end; end;
That's all.