determining if an SQL database exists, etc.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BobLewiston
    New Member
    • Feb 2009
    • 93

    determining if an SQL database exists, etc.

    Could someone please give me the simplest possible C# code snippets / SQL queries to determine whether:

    * a given SQL database exists,
    * a given existing SQL database is accessible, and
    * a given table exists within a given existing SQL database?

    Thanks for whatever help anyone can provide.
  • vecs
    New Member
    • Apr 2009
    • 3

    #2
    List all accessible databases on server:
    Code:
    EXEC master..sp_databases
    List all system tables, tables, views in current database:
    Code:
    EXEC sp_tables
    List all tables with given name in specific database:
    Code:
    USE [I]database_name[/I]
    EXEC sp_tables @table_name = '_user'

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      There are system tables that you can use to check if it's existing master.sysdatab ases; sysobjects - for the tables...to check if it's accessible, let your front-end connection handle it. Establish your connection and just throw an error. "Accessible " is a relative. It might be there but depending on the user account, it might not be "accessible "


      --- CK

      Comment

      Working...