如何判断sqlserver2000数据库中的某个表是否存在?

解决方案 »

  1.   

    if exists(select 1 from sysobjects where name='tb_ZWFBT')
     select 1
      

  2.   

    if exists(select 1 from sysobjects where name='你的表名')
     select '存在这个表'
      

  3.   

    if exists(select name from sysobjects where name='表名' and type='U')排除存储过程和视图及系统表等。
      

  4.   

    if exits(select * from sysobjects where id = object_id('yourtable') and xtype = 'u')
      

  5.   

    几位老兄我是要在delphi的query里判断表是否存在,如果不存在就建个新表。
      

  6.   

    听了这话楼上的全部晕倒(开玩笑:)
    with Query1, SQL do
    begin
      Close;
      Clear;
      Add('if not exits(select * from sysobjects where id = object_id('''yourtable''') and xtype = 'u' create table yourtable (aa int, bb varchar(10)');
      ExecuteSQL;
    end;
      

  7.   

    错了with Query1, SQL do
    begin
      Close;
      Clear;
      Add('if not exits(select * from sysobjects where id = object_id(''yourtable'') and xtype = 'u') create table yourtable (aa int, bb varchar(10)');
      ExecuteSQL;
    end;
      

  8.   

    多谢各位,做个总结:
    query1.sql.Clear;
    query1.add('if not exits(select * from sysobjects ');
    query1.add('where id = object_id(''yourtable'') and xtype = ''u'')');
    query1.add(' create table yourtable (aa int)');
    query1.ExecSQL;