判断数据库中表是否存在

sql server 

if   exist(select   *   from   sysobjects   where   id=object_id('table1')   )   then    
  drop   table1  

 

if   exists(select   top   1   id   from   tablename1)  

 

用 if   exists(select   1   from   tablename1)     没必要什么top   几,也没必要选哪个字段。 

 

 

 

 

SQlite

function TableExist(Query:TZquery;tname:string):boolean;
begin
//缺省情况表名区分大小写

Query.sql.text:='Select Count(*) as Num from  sqlite_master  where (type=''table'') and (table='''+tname+''')';
Query.Open;
result:=(Query.fieldbyname('Num').asinteger>0);
end; 

你可能感兴趣的:(判断数据库中表是否存在)