yo suelo utilizar esta función para añadir campos a una tabla en ejecución. Se le pasa el nombre de la tabla, el nombre del campo, el tipo del campo y la posición (la función es mejorable, pero bueno, es una opción
)
Código:
function CheckCampo(Tabla, Campo, Tipo : String; Posicion: Integer): Boolean;
var
tCambios : TIbTable;
QryCambios : TIbQuery;
begin
Result := False;
tCambios := TIBTable.Create(Application);
try
tCambios.Database := BDades.IBDatabase1;
tCambios.TableName := Tabla;
tCambios.Open;
if tCambios.FindField( Campo ) = nil then
begin
tCambios.Close;
QryCambios := TIbQuery.Create(Application);
try
QryCambios.Database := BDades.IBDatabase1;
QryCambios.SQL.Add('ALTER TABLE '+ TABLA + ' Add "'+ CAMPO +'" ' + TIPO );
try
QryCambios.ExecSQL;
BDades.IBTransaction1.CommitRetaining;
if Posicion >= 0 then
begin
if NOT BDades.IBTransaction1.InTransaction then
BDades.IBTransaction1.StartTransaction;
QryCambios.Close;
QryCambios.SQL.Clear;
QryCambios.SQL.Add('UPDATE RDB$RELATION_FIELDS SET RDB$FIELD_POSITION=' + IntTostr(POSICION) );
QryCambios.SQL.Add('WHERE RDB$FIELD_NAME=' + '''' + CAMPO + '''' +
' AND RDB$RELATION_NAME= ' + '''' + TABLA + '''' );
QryCambios.ExecSQL;
BDades.IBTransaction1.CommitRetaining;
fSplash.ProgressBar1.StepIt;
end;
Result := True;
except
on e: exception do
MessageDlg( 'Imposible reestructurar Tabla ' + Tabla +
'. No es posible acceder a la tabla '+ BDades.IBDatabase1.Databasename +
#13 + e.Message, mtError, [mbOk], 0);
end;
finally
QryCambios.Free;
end;
end
else Result := True;
if tCambios.Active then tCambios.Close;
finally
FreeAndNil(tCambios);
end;
end;
Espero te sirva