请问:如何用sql语句判断一个表已经存在?

ilbj 2002-08-30 03:09:04
请问:如何用sql语句判断一个表已经存在?不管它有无数据。
...全文
71 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ghls 2002-08-30
  • 打赏
  • 举报
回复
有些问题,只要自己动手试一下就知道了。
jzhaohua 2002-08-30
  • 打赏
  • 举报
回复
告诉大家一个好方法吧, 不需要使用系统表

string ls_sql
ls_sql = "SELECT * FROM " + ls_table + " WHERE 1=2"
EXECUTE IMMEDIATE :ls_sql ;
IF SQLCA.SQLCode = 0 THEN
messagebox("系统提示","数据库中有这张表 !")
END IF


呵呵
分太少了
konrong 2002-08-30
  • 打赏
  • 举报
回复
execute immediate "if exists (select * from sysobjects where id = object_id(N'[dbo].[cf_xs]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[cf_xs]";
mongtze 2002-08-30
  • 打赏
  • 举报
回复
判断一个表是否存在,可以用如下语句:
datetime ld_date

SELECT getdate() INTO :ld_date FROM tablename;
//表存在就可以取出服务器时间,否则,不可以。
if sqlca.sqlcode = 0 then
表存在
else
表不存在
end if
dfz_fan 2002-08-30
  • 打赏
  • 举报
回复
string ls_tablename
long ll_countnum

SELECT count(*)
INTO :ll_countnum
FROM dbo.sysobjects
WHERE dbo.sysobjects.name = :ls_tablename and dbo.sysobjects.type='U';

if ll_countnum > 0 then
存在
esle
不存在
end if
xxxyyyzzzwww 2002-08-30
  • 打赏
  • 举报
回复
学习
hjd_cw 2002-08-30
  • 打赏
  • 举报
回复
int li_count
select count(*) into :li_count
from tab_name;
if sqlca.sqlcode <> 0 then
MessageBox('','表不存在或连接错误')
end if
这样做不是十分准确,但比较通用。
对 sybase 或 MsSQL 之类的数据库,可以从 sysobjects 系统表里查。
myclife 2002-08-30
  • 打赏
  • 举报
回复
假设表名:TABN

if(select * from sysobjects where name='TABN'and type='U')
drop table TABN


select count(*) from sysobjects where name='TABN' and type='U'

检查行数

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧