EPUB | CHM | PDF

TMySQLTable.Properties.Exists

Top Previous Next

Indicates whether the underlying database table exists.

Syntax:

property Exists: Boolean;

Description:

Read Exists at runtime to determine whether a database table exists. If the table does not exist, create a table from the field definitions and index definitions using the CreateTable method. This property is read-only.

Example:

The following example shows how to create a table.

// Don't overwrite an existing table
if not MySQLTable1.Exists then
 begin
  with MySQLTable1 do begin
// The Table component must not be active
    Active := False;
// First, describe the type of table and give
// it a name
    DatabaseName := 'DBDEMOS';
    TableName := 'CustInfo';
// Describe the fields in the table
    with FieldDefs do begin
      Clear;
      with AddFieldDef do begin
        Name := 'Field1';
        DataType := ftInteger;
        Required := True;
      end;
      with AddFieldDef do begin
        Name := 'Field2';
        DataType := ftString;
        Size := 30;
      end;
     end;
// Describe any indexes
    with IndexDefs do begin
      Clear;
      with AddIndexDef do begin
        Name := '';
        Fields := 'Field1';
        Options := [ixPrimary];
       end;
      with AddIndexDef do begin
        Name := 'Fld2Indx';
        Fields := 'Field2';
        Options := [ixCaseInsensitive];
      end;
    end;
// Call the CreateTable method to create the table
    CreateTable;
  end;
end;