SqlConnection question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam Johnson

    #1

    SqlConnection question

    Hi

    how can I test if a specific table on an SQL- Server (that I'm connected to) exists or not

    Thank
    Sam
  • Bill Manring

    #2
    RE: SqlConnection question

    Sam

    You could run a query against the sysobjects table in the databse you are connected to

    The query could look something like this

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MyTableName]') and OBJECTPROPERTY( id, N'IsUserTable') = 1

    Hope this help

    Comment

    • Mary Chipman

      #3
      Re: SqlConnection question

      If you're already connected to a specific database you can use the
      following query to determine if the table exists.

      SELECT table_name FROM INFORMATION_SCH EMA.TABLES
      WHERE table_type = 'BASE TABLE'

      The other choice for table_type is 'VIEW'.

      --Mary

      On Sun, 18 Apr 2004 06:41:02 -0700, "Sam Johnson"
      <anonymous@disc ussions.microso ft.com> wrote:
      [color=blue]
      >Hi,
      >
      >how can I test if a specific table on an SQL- Server (that I'm connected to) exists or not?
      >
      >Thanks
      >Sam[/color]

      Comment

      • Mary Chipman

        #4
        Re: SqlConnection question

        If you're already connected to a specific database you can use the
        following query to determine if the table exists.

        SELECT table_name FROM INFORMATION_SCH EMA.TABLES
        WHERE table_type = 'BASE TABLE'

        The other choice for table_type is 'VIEW'.

        --Mary

        On Sun, 18 Apr 2004 06:41:02 -0700, "Sam Johnson"
        <anonymous@disc ussions.microso ft.com> wrote:
        [color=blue]
        >Hi,
        >
        >how can I test if a specific table on an SQL- Server (that I'm connected to) exists or not?
        >
        >Thanks
        >Sam[/color]

        Comment

        • Val Mazur

          #5
          Re: SqlConnection question

          Hi Sam,

          You could query system tables. but if you want to be generic, then use
          OpenSchema method if ADO or GetOledbSchemaT able method if ADO.NET



          --
          Val Mazur
          Microsoft MVP


          "Sam Johnson" <anonymous@disc ussions.microso ft.com> wrote in message
          news:6E8AF8A0-6818-400D-AFAB-A1387201F54B@mi crosoft.com...[color=blue]
          > Hi,
          >
          > how can I test if a specific table on an SQL- Server (that I'm connected
          > to) exists or not?
          >
          > Thanks
          > Sam[/color]


          Comment

          • Val Mazur

            #6
            Re: SqlConnection question

            Hi Sam,

            You could query system tables. but if you want to be generic, then use
            OpenSchema method if ADO or GetOledbSchemaT able method if ADO.NET



            --
            Val Mazur
            Microsoft MVP


            "Sam Johnson" <anonymous@disc ussions.microso ft.com> wrote in message
            news:6E8AF8A0-6818-400D-AFAB-A1387201F54B@mi crosoft.com...[color=blue]
            > Hi,
            >
            > how can I test if a specific table on an SQL- Server (that I'm connected
            > to) exists or not?
            >
            > Thanks
            > Sam[/color]


            Comment

            Working...