EPUB | CHM | PDF

TPSQLTable.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 PSQLTable1.Exists then
 begin
  with PSQLTable1 do begin
// The Table component must not be active
    Active := False;
// Define table's type and name
    DatabaseName := 'DBDEMOS';
    TableName := 'CustInfo';
// Define table's fields
    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;
// Define 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;
// Create the table
    CreateTable;
  end;
end;