Home > Database > Mysql Tutorial > body text

SQL语句判断已知表是否存在

WBOY
Release: 2016-06-07 17:47:12
Original
1777 people have browsed it

 

 

 

 

 

 

怎样用SQL语句来判断已知表是否存在

答:具体解决方法如下:

注释:以下代码为通常的引用Dao做的一模块


Function fExistTable(strTableName As String) As Integer
Dim db As Database
Dim i As Integer   
    Set db = DBEngine.Workspaces(0).Databases(0)   
    fExistTable = False
    db.TableDefs.Refresh
    For i = 0 To db.TableDefs.Count - 1
        If strTableName = db.TableDefs(i).Name Then
            'Table Exists
            fExistTable = True
            Exit For
        End If
    Next i
    Set db = Nothing
End Function

Private Sub 命令0_Click()
fExistTable
End Sub

用该事件出现‘参数不可选’的错误。仔细研究,发现fExistTable缺少参数,即已知表名没有在代码中反应。


修改为:


Private Sub 命令0_Click()
fExistTable(”需判断的已知表名”)
End Sub

End Sub不再报错。仔细分析,其实是用 ”已知表名” 通过Dao判断中是否存在,如果fExistTable的值为True就是存在,否则就是不存在。


解决问题后,忽然想起Access数据库也有系统表,存放有对象名,是否做一查询来判定呢


经验证,可以实现需求。如果Qty>0,即表示表已存在,否则就表示不存在。


SELECT Count(*) AS Qty
FROM MSysObjects
WHERE (((MSysObjects.Name) Like "需判断的已知表名"));

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template