var mytables:tstringlist; begin mytables:=tstringlist.Create ; adoconnect.GetTableNames(mytables); if not (mytables.IndexOf(findtablename)=-1) then showmessage('find');
if exists (select * from sysobjects where id = object_id(N'[dbo].[aaa]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
在系统表里查询一下,好像是sysobjects吧
做成函数: function TMisData.My_ExistTable(_TableName:String):Boolean; var MyList: TStringList; Index: Integer; begin MyList := TStringList.Create; ADOConnection1.GetTableNames(MyList, False); try MyList.Sort; { Find will only work on sorted lists! } if MyList.Find(_TableName, Index) then Result:=True else Result:=False; finally MyList.Free; end; end;
如果再加上对_TableName的验证就更完整了。
可先写在SQL SERVER2000中写一个存储过程为: if exists (select * from sysobjects where type='U' and name='aaa') drop table aaa 检查表aaa是否存在,存在即删除 再在DELPHI调用此存储过程即可
if exists(select * from sysobjects where name='aa' and type='T') then .....
来迟一步 if exists(select * from sysobjects where name='aaa' ...
mytables:tstringlist;
begin
mytables:=tstringlist.Create ;
adoconnect.GetTableNames(mytables);
if not (mytables.IndexOf(findtablename)=-1) then
showmessage('find');
function TMisData.My_ExistTable(_TableName:String):Boolean;
var
MyList: TStringList;
Index: Integer;
begin
MyList := TStringList.Create;
ADOConnection1.GetTableNames(MyList, False);
try
MyList.Sort; { Find will only work on sorted lists! }
if MyList.Find(_TableName, Index) then
Result:=True
else
Result:=False;
finally
MyList.Free;
end;
end;
if exists (select * from sysobjects where type='U' and name='aaa')
drop table aaa
检查表aaa是否存在,存在即删除
再在DELPHI调用此存储过程即可
.....
if exists(select * from sysobjects where name='aaa' ...
从SQLSERVER里导出一个数据库的结构,并且要求包含检测用删除语句在文件的开头即可看到大量的“若存在XXX表,则删除”。