写一个SQL,先判断某表是否存在,如果存在,那么就删除该表~!高手指教~

解决方案 »

  1.   

    你可以用SQL Server企业管理器,生成某表的SQL源文件,然后看看SQL源文件就可以了,还免得您自己写了:)
      

  2.   

    if exists (select * from 你的表名)
    drop table 你的表名
      

  3.   

    adoquery1.close;
    adoquery1.sql.clear;
    adoquery1.sql.add('select *from sysobjects');
    adoquery1..sql.add('where name ='''+你要判断的表+'''');//表是根据需要可变的
    adoquery1.sql..add('order by name ');
    adoquery1.open;
    if adoquery1.recordcount<=0 then 
    begin
    删除
    end;
      

  4.   

    也可以
    if exists (select * from  sysdatabases where name ='你的表')
    drop database 你的表
      

  5.   

    if exists (select * from 你的表名)
    drop table 你的表名
    上面这个只能在有表的并且有记录的情况下使用if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[表名]
    这个管用
      

  6.   

    if object_id('要检测的表名') is null
    print 'Found'
    else print 'No' 
    或者用楼上几位的都可以具体请查看SQL帮助