在该库中的系统表SysColumns中找到该表名则说明存在。

解决方案 »

  1.   

    select yourtablename from sysobjects
      

  2.   

    在客户端用查询语句查询:
    select name from sysobjects where name='yourtablename' and type='U';
    if rs.eof then
    没有表
    end if
    在服务器端判断
    1。if exists(select name from sysobjects where name='yourtablename' and type='U')
    表存在或者
    2。
    if object_id('yourtablename') is null 
    表不存在
      

  3.   

    if(objectid(tablename)>0)
    begin
    drop table tablename
    end
    create table tablename
      

  4.   

    不管什么情况,先删表,用设陷错误来 处理 没有表可删的情况: 
    on error resume next 
    'drop table 
    on error goto next 
    'create table
        
      

  5.   

    写错了,改:
    不管什么情况,先删表,用设陷错误来 处理 没有表可删的情况: 
    on error resume next 
    'drop table 
    on error goto 0
    'create table
          
      

  6.   

    icevi:
    可是这样的话,软件运行中:还是会先出现错误,这时候软件就中止了,不能执行下面的错误处理语句,......
    另外,goto 0是跳到哪里了啊?
      

  7.   

    各位高手,你们的办法我去试了,可是我的表名要用变量给出(因为事先不固定么),是用这样的形式:
    exec( ' if(object_id('+ @tablename + ') is not null) 
            drop table dbo.'+ @tablename )
    所以表名两边的那个单引号就打不进去了,也就运行不了这个语句了,怎么办啊,我急死了!
      

  8.   

    luna_sea(高野辉) :你没明白我的意思。
    上面的语句第一句:on error resume next  就是若第二句“drop table”有错,就跳不执行第二句。
    on error goto 0 就是不处理设陷错误。这里是用来取消第一句的作用的。因为这四句完后下面的语句可能还是要设陷错误处理的。若这个表存在,会执行第二句及第四句。
    若这个表不存在,只执行第四句。