MSAccess判断表字段是否存在及添加字段
一般用于版本控制,代码如下:
delphi10.4.1,firedac fdquery组件,其他语言看下sql就行。
procedure TfrmMain.upDB();
var
find: boolean;
i: integer;
begin
find := False;
Qt.Close;
Qt.Open('select top 1 * from tAccountDetail');
for i := 0 to Qt.FieldCount - 1 do
begin
if Qt.Fields[i].FieldName = 'FP34' then // FP34|其他奖金
begin
find := true;
Break;
end;
end;
if not find then
begin
try
Qt.Close;
Qt.SQL.Text := 'alter table tAccountDetail add FP34 money DEFAULT 0';
Qt.ExecSQL;
Qt.SQL.Text := 'update tAccountDetail set FP34=0';
Qt.ExecSQL;
Qt.SQL.Text := 'insert into tSelTemp2(fname,fcode)'
+ ' values(''其他奖金'',''FP34'')';
Qt.ExecSQL;
except
//
end;
end;
end;
来源:https://www.offeu.com/www/index_id_255.html
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.049190998077393 seconds