ADO方式下判斷資料表是否存在

2021-04-01 15:43:16 字數 1022 閱讀 8324

檢視:[大字型 中字型 小字型]

前段時間做乙個管理系統的時候,乙個朋友問我不用資料庫,用excel可以做不,當時在做的過程中出了一一些的問題,就想現在說到的這樣,我在判斷資料是否存在的時候有一些問題,現在在網上找了點資料,整理後貼在這裡.

下面構造兩個可過載的函式,用於在ado方式下判斷資料庫的資料表是否存在。

//函式一:

function tableexist( padocmd: tadocommand; pctable : string ) : boolean ; overload ;

var cerror : string ;

begin

ado_command_exec( padocmd, 'select top 1 from ' + pctable , cerror );

result := ( cerror = '' );

end ;

//函式二:

function tableexist( pconn:tadoconnection; pctable : string ) : boolean ; overload ;

var tmpfldlist : tstrings ;

nloop : integer ;

begin

result := false ;

tmpfldlist := tstringlist.create ;

pconn.gettablenames( tmpfldlist, true ); // 包含系統表

for nloop := 0 to tmpfldlist.count - 1 do

begin

if uppercase( tmpfldlist[nloop] ) = uppercase( pctable ) then

begin

result := true ;

break ;

end;

end;

tmpfldlist.free ;

end;

SQL判斷資料表是否存在

最近重新做開發,又自己動手寫了sql語句,所以把一些東西記錄到這裡,為了加深印象,大家一起交流。假設有一張表,名為 personale if exists select from sysobjects where object id n personale and objectproperty id...

判斷臨時表是否存在

if object id tempdb.t is not null drop table t if objectproperty object id tempdb.t istable 1 print authors is a table else if objectproperty object i...

sqlserver判斷表是否存在

1 判斷資料表是否存在 方法一 use yourdb goif object id n tablename n u is not null print 存在 else print 不存在 例如 use fireweb goif object id n temp tbl n u is not null...