在删除一个表之前,我想先判断一下这个表是否存在,请问该如何实现啊?

解决方案 »

  1.   

    好像没看到这种SQL语句,我一般是用:Session.GetTableNames方法来判断表是否存在
      

  2.   

    var
      List: TStringList;
    begin
      List:=TStringList.Create;
      try
        ADOConnection.GetTableNames(List, True);
        if List.IndexOf('TableNaem')=-1 then
          //不存在
        else
          //存在
      finally
        List.Free
      end
    end
      

  3.   

    用下面语名即可:if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[表名]
      

  4.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[表名]