在VB中应该如何判断一个表是否在SQL SERVER中存在?
比如:在VB界面的一个TEXT文本框中输入一个表的表名,那么在VB界面中应该怎样用代码来实现判断这个表是否在SQL SERVER中存在??如果不存在就建立一个以TEXT文本框的内容命名的表

解决方案 »

  1.   


    select * from sysobjects where xtype='U' and object_name(id)=N'tb'
      

  2.   

    sql="IF OBJECT_ID('" & text.text & "') IS NULL create table " & text.text & "...."
      

  3.   

    sql="select * from sysobjects where xtype=N'U' and object_name(id)=N'"& text1.text&"'"
    执行上面这句,如果有表,则有记录返回,反之,无记录返回~
      

  4.   

    strSQl = "select * from dbo.sysobjects where id=object_id(N'[dbo].[" _
            & text1 & "]')and objectproperty (id,N'isusertable')=1"
      

  5.   

    sql="IF OBJECT_ID('" & text.text & "') IS NULL create table " & text.text & "...."
      

  6.   

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    说明表存在接下来就是如何在VB中调用SQL语句了,这个你查一下VS2003帮助或Microsoft在线帮助
      

  7.   

    select * from sysobjects where xtype='U' and id=object_id('table')
    如果返回值为空,就表示没有该数据表,反之