Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Checking database has a table.

Checking database has a table.

Scheduled Pinned Locked Moved Database
databasetutorial
14 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y yuvarajujogi

    How to check whether a database has a table out of that database

    R Offline
    R Offline
    RDBurmon
    wrote on last edited by
    #4

    It depends which database you are using. If you are using MSAccess , then you can write the code in any language and using TABLE collection you can count and note the tables name If you are using SQL SERVER , then here is querey "SELECT * FROM Sys.Tables" If you are using MySQL , then here is query SHOW [FULL] TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]

    1 Reply Last reply
    0
    • Y yuvarajujogi

      How to check whether a database has a table out of that database

      P Online
      P Online
      PIEBALDconsult
      wrote on last edited by
      #5

      Yet another way to get a list of tables in an ADO.net-supported database:

      System.Data.Common.DbConnection con =
      this.command.Connection as System.Data.Common.DbConnection ;

      if ( con != null )
      {
      System.Data.DataTable temp = con.GetSchema
      (
      "TABLES"
      ) ;

      temp.DefaultView.RowFilter = "TABLE\_TYPE='TABLE' OR TABLE\_TYPE='BASE TABLE'" ;
      temp.DefaultView.Sort = "TABLE\_NAME" ;
      
      1 Reply Last reply
      0
      • Y yuvarajujogi

        How to check whether a database has a table out of that database

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #6

        yuvarajujogi wrote:

        How to check whether a database has a table out of that database

        What are you going to do if it doesn't?

        Y 1 Reply Last reply
        0
        • Y yuvarajujogi

          How to check whether a database has a table out of that database

          M Offline
          M Offline
          Mohibur Rashid
          wrote on last edited by
          #7

          Hey, What database are you talking about? MySQL, Microsoft SQL Server ORACLE ....

          Y 1 Reply Last reply
          0
          • M Mohibur Rashid

            Hey, What database are you talking about? MySQL, Microsoft SQL Server ORACLE ....

            Y Offline
            Y Offline
            yuvarajujogi
            wrote on last edited by
            #8

            Sql Server

            M L 2 Replies Last reply
            0
            • Y yuvarajujogi

              Sql Server

              M Offline
              M Offline
              Mohibur Rashid
              wrote on last edited by
              #9

              Once Again, What version of SQL Server? SQL Server 2000 SQL Server 2003 or What?

              1 Reply Last reply
              0
              • J jschell

                yuvarajujogi wrote:

                How to check whether a database has a table out of that database

                What are you going to do if it doesn't?

                Y Offline
                Y Offline
                yuvarajujogi
                wrote on last edited by
                #10

                I want to create a table in that database similar to the table in another database.

                K 1 Reply Last reply
                0
                • Y yuvarajujogi

                  Sql Server

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #11

                  You can use this code to check if a table exists.

                  IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MyTable]') AND type in (N'U'))
                  PRINT 'MyTable exists.'
                  ELSE
                  PRINT 'MyTable does not exist.'

                  1 Reply Last reply
                  0
                  • Y yuvarajujogi

                    I want to create a table in that database similar to the table in another database.

                    K Offline
                    K Offline
                    Karthik Harve
                    wrote on last edited by
                    #12

                    try with this..

                    If Object_ID('dbo.MyTable') IS NOT NULL
                    PRINT 'MyTable Exists'
                    Else
                    PRINT 'MyTable Not Exists'

                    with regards Karthik Harve

                    1 Reply Last reply
                    0
                    • Y yuvarajujogi

                      How to check whether a database has a table out of that database

                      K Offline
                      K Offline
                      Karthik Harve
                      wrote on last edited by
                      #13

                      try with this..

                      If Object_ID('dbo.MyTable') IS NOT NULL
                      PRINT 'MyTable Exists'
                      Else
                      PRINT 'MyTable Not Exists'

                      with regards Karthik Harve

                      L 1 Reply Last reply
                      0
                      • K Karthik Harve

                        try with this..

                        If Object_ID('dbo.MyTable') IS NOT NULL
                        PRINT 'MyTable Exists'
                        Else
                        PRINT 'MyTable Not Exists'

                        with regards Karthik Harve

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #14

                        If there is a view or stored procedure with the same name, this script will fail.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups