呵呵 分拿来吧
var
TempStrings:TStringList;
begin
if adtblWater.Active then //连接要初始化ID的表的ADOTable
adtblWater.Close;
with ADOQuery1 do
begin
Close;
Sql.Clear;
Sql.Add('delete from water');
ExecSQl;
adtblWater.GetIndexNames(TempStrings);
if TempStrings.IndexOf('PrimaryKey')<>-1 then
begin
Close;
Sql.Clear;
Sql.Add('alter table water drop constraint primarykey');
ExecSql;
end;
frmDM.adtblWater.GetFieldNames(TempStrings);
if TempStrings.IndexOf('id')<>-1 then
begin
Close;
Sql.Clear;
Sql.Add('alter table water drop column id');
ExecSql;
end;
Close;
Sql.Clear;
Sql.Add('alter table water add column id counter(1,1)');
ExecSql;
Close;
Sql.Clear;
Sql.Add('alter table water alter column id counter(1,1)');
ExecSQL;
Close;
Sql.Clear;
Sql.Add('alter table water add constraint primarykey primary key (id)');
ExecSql;
end;
end
绝对可行 我的程序现在用。