select * 
from sysobjects  
where xtype='u' and name='databasename'

解决方案 »

  1.   

    保存在系统表里
    use master
    select name from sysdatabases where name='attend'其中attend为数据库名,如果有则返回
      

  2.   

    'One Test Program
    'Add the Reference of "microsoft SQLDMO Object Library"
    'Add a ComboBox On the Form,named cboServer
    'Add a Checkbox On the Form,named chkNTSecurity
    'Add two textbox On the Form,named txtUID,txtPWD
    'Add a CommandBox On the Form,named cmdConnect
    'Add a textbox On the Form,named txtDatabase(the Database you want to check whether exist)
    'Add a CommandBox On the Form,named cmdCheck
    'This Program is to Show How to Use SQLDMO to Check a Database whether ExistDim oSQLServer As New SQLDMO.SQLServerPrivate Sub cboServer_Change()
        cmdConnect.Enabled = True
    End SubPrivate Sub chkNTSecurity_Click()    If chkNTSecurity.Value = vbChecked Then
            txtUID.Enabled = False
            txtPWD.Enabled = False
        End If
        
    End SubPrivate Sub cmdCheck_Click()
    '    lstDatabases.Text = txtDataBase.Text
    '    If lstDatabases.ListIndex <> -1 Then
    '        MsgBox "The DataBase is Exist!"
    '    Else
    '        MsgBox "The DataBase isn't Exist!"
    '    End If
        Dim oDatabase As SQLDMO.Database
        
        On Error GoTo CheckError
        
        ' Check the databases whether exist
        For Each oDatabase In oSQLServer.Databases
            If oDatabase.Status <> SQLDMODBStat_Inaccessible Then
                '
                If UCase(txtDatabase.Text) = UCase(oDatabase.Name) Then
                    MsgBox "The Database You want to check is exist!"
                    Exit Sub
                End If
            End If
        Next oDatabase
        MsgBox "The Database You want to check isn't exist!"
        Exit Sub
         
    CheckError:
        SQLDMOError
        
    End SubPrivate Sub cmdConnect_Click()    On Error GoTo ConnectError
        
        MousePointer = vbHourglass
        
        ' Setup a secure login for NT security
        If chkNTSecurity.Value = vbChecked Then
            oSQLServer.LoginSecure = True
        End If
        
        ' Connect to the selected SQL Server system
        oSQLServer.Connect cboServer.Text, txtUID.Text, txtPWD.Text
        
        'Disabled the Connect Button
        cmdConnect.Enabled = False
            MousePointer = vbDefault
        Exit Sub
        
    ConnectError:
        SQLDMOError
        MousePointer = vbDefault
    End SubPrivate Sub Form_Load()    Dim oApplication As New SQLDMO.Application
        Dim oServerGroup As SQLDMO.ServerGroup
        Dim oRegisteredServer As SQLDMO.RegisteredServer
        
        cboServer.Clear
        ' Process all the server groups
        For Each oServerGroup In oApplication.ServerGroups
            ' Process each registered server
            For Each oRegisteredServer In oServerGroup.RegisteredServers
                ' Add each name to the combobox
                cboServer.AddItem oRegisteredServer.Name
            Next
        Next
        
        Set oRegisteredServer = Nothing
        Set oServerGroup = Nothing
        Set oApplication = Nothing
        
    End SubPublic Function SQLDMOError()
        
        Dim sErrorMsg As String
        
        sErrorMsg = Err.Source & " Error: " & _
                    Err.Number - vbObjectError & ": " & Err.Description    SQLDMOError = MsgBox(sErrorMsg, vbOKOnly, "SQL-DMO Error")End Function
    Private Sub cboServer_Click()
        cmdConnect.Enabled = True
    End Sub
      

  3.   

    查看一下SQL Server中的一些stored proc.会有启示:if exist ( select * from xxxx)